JSon from VB.NET

Man of Honour
Joined
17 Feb 2003
Posts
29,640
Location
Chelmsford
Hi,


I have created a WCS API which I have tested from SOAPUI using the JSon, so I know that side all works 100%.

I now want to invoke the Json from a vb.net app, but I've no idea where to start. Some Googling around yesterday seems very vague and complicated, and I'm sure it's not.

Here's an example of the string I have built that i'd like to call.




Code:
            JsonRequest = "{"
            JsonRequest += """UserId"":""MyUserID"" , ""BankBIC"","
            JsonRequest += "{"
            JsonRequest += """BIC"" :""" + BankBIC.BIC + ""","
            JsonRequest += """SortCode"" :""" + BankBIC.SortCode + ""","
            JsonRequest += """Suffix"" :""" + BankBIC.Suffix + ""","
            JsonRequest += """BankName"" :""" + BankBIC.BankName + ""","
            JsonRequest += """City"" :""" + BankBIC.City + ""","
            JsonRequest += """CountryName"" :""" + BankBIC.CountryName + ""","
            JsonRequest += """CountryCode"" :""" + BankBIC.CountryCode + ""","
            JsonRequest += """CountryAlphaCode"" :""" + BankBIC.CountryAlphaCode + ""","
            JsonRequest += """Status"" :""" + BankBIC.Status + ""","
            JsonRequest += "}"
            JsonRequest += "}"

If any one has any simple example to help, that would be great.

Thanks
 
Soldato
Joined
1 Feb 2006
Posts
3,396
Load/Save the json string into an object using NewtonSoft:

Public Shared Function LoadFromString(Of T)(ByVal json As String) As T?
If Not String.IsNullOrEmpty(json) Then
Return JsonConvert.DeserializeObject(Of T)(json)
End If
Return "default"
End Function

Public Shared Function SaveToString(Of T)(ByVal item As T) As String
Return JsonConvert.SerializeObject(item)
End Function

usage:

Dim jsonString As String = SaveToString(item)
Dim obj = LoadFromString(Of BankBIC)(jsonString)
 
Last edited:
Back
Top Bottom