Add Data In Json FIle

  1. <Services.WebMethod()>  
  2. Public Shared Function SaveUser(ByVal id As String, ByVal fName As String, ByVal lName As String) As String  
  3. Try  
  4. Dim str As String = ""  
  5. Dim sr As StreamReader = New StreamReader("D:\manish\JsonForm\demo.txt")  
  6. str = sr.ReadToEnd()  
  7. Dim cont As New List(Of Class2)  
  8. cont = JsonConvert.DeserializeObject(Of List(Of Class2))(str)  
  9. Dim Person As New Class2  
  10. Person.id = id  
  11. Person.firstName = fName  
  12. Person.lastName = lName  
  13. cont.Add(Person)  
  14. For Each dt In cont  
  15. Dim list As New List(Of Class2)  
  16. Next  
  17. Dim a As String  
  18. a = JsonConvert.SerializeObject(cont, Formatting.Indented)  
  19. Dim liset As New Class1  
  20. sr.Dispose()  
  21. Dim sw As StreamWriter = New StreamWriter("D:\manish\JsonForm\demo.txt")  
  22. sw.Write(a)  
  23. sw.Dispose()  
  24. MsgBox(a)  
  25. Catch ex As JsonSerializationException  
  26. MsgBox(ex.Message)  
  27. End Try  
  28. End Function  
  29.    
  30. OutPut Of this Code ::  
  31.    
  32. [  
  33. {  
  34. "id""11",  
  35. "firstName""Manish",  
  36. "lastName""Patel"  
  37. },  
  38. {  
  39. "id""1008",  
  40. "firstName""Manish",  
  41. "lastName""Poplauu"  
  42. },  
  43. {  
  44. "id""1",  
  45. "firstName""aa",  
  46. "lastName""aa"  
  47. },  
  48. {  
  49. "id""22",  
  50. "firstName""ee",  
  51. "lastName""ee"  
  52. },  
  53. {  
  54. "id""1",  
  55. "firstName""manish",  
  56. "lastName""pilaiui"  
  57. },  
  58. {  
  59. "id""1002",  
  60. "firstName""manish",  
  61. "lastName""kanani"  
  62. },  
  63. {  
  64. "id""1005",  
  65. "firstName""Manish",  
  66. "lastName""PAtel"  
  67. },  
  68. {  
  69. "id""1106",  
  70. "firstName""Kalpesh",  
  71. "lastName""Kanani"  
  72. },  
  73. {  
  74. "id""aaa",  
  75. "firstName""aaa",  
  76. "lastName""aaa"  
  77. },  
  78. {  
  79. "id""101",  
  80. "firstName""Mani",  
  81. "lastName""Khushi"  
  82. }  
  83. ]