<Services.WebMethod()>
Public Shared Function SaveUser(ByVal id As String, ByVal fName As String, ByVal lName As String) As String
Try
Dim str As String = ""
Dim sr As StreamReader = New StreamReader("D:\manish\JsonForm\demo.txt")
str = sr.ReadToEnd()
Dim cont As New List(Of Class2)
cont = JsonConvert.DeserializeObject(Of List(Of Class2))(str)
Dim Person As New Class2
Person.id = id
Person.firstName = fName
Person.lastName = lName
cont.Add(Person)
For Each dt In cont
Dim list As New List(Of Class2)
Next
Dim a As String
a = JsonConvert.SerializeObject(cont, Formatting.Indented)
Dim liset As New Class1
sr.Dispose()
Dim sw As StreamWriter = New StreamWriter("D:\manish\JsonForm\demo.txt")
sw.Write(a)
sw.Dispose()
MsgBox(a)
Catch ex As JsonSerializationException
MsgBox(ex.Message)
End Try
End Function
OutPut Of this Code ::
[
{
"id": "11",
"firstName": "Manish",
"lastName": "Patel"
},
{
"id": "1008",
"firstName": "Manish",
"lastName": "Poplauu"
},
{
"id": "1",
"firstName": "aa",
"lastName": "aa"
},
{
"id": "22",
"firstName": "ee",
"lastName": "ee"
},
{
"id": "1",
"firstName": "manish",
"lastName": "pilaiui"
},
{
"id": "1002",
"firstName": "manish",
"lastName": "kanani"
},
{
"id": "1005",
"firstName": "Manish",
"lastName": "PAtel"
},
{
"id": "1106",
"firstName": "Kalpesh",
"lastName": "Kanani"
},
{
"id": "aaa",
"firstName": "aaa",
"lastName": "aaa"
},
{
"id": "101",
"firstName": "Mani",
"lastName": "Khushi"
}
]In this blog we will see How to add Data If txt file in Json Format.
