Reputation: 211
I have seen there are many examples in C# version. Same also as DataContractJsonSerializer
class in MSDN. Anyone please help me on VB.net version?
Upvotes: 0
Views: 839
Reputation: 3186
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ser As New DataContractJsonSerializer(GetType(Product))
Using fs As FileStream = File.OpenRead("c:\jsonText.txt")
Dim product As Product = TryCast(ser.ReadObject(fs), Product)
MessageBox.Show("Product Name: " & product.Name)
End Using
End Sub
End Class
<Serializable()> _
Public Class Product
Public Name As String
End Class
End Namespace
Here is the vb.net sample taken from msdn and converted by developerfusion converter
Upvotes: 0
Reputation: 3870
Here's the same source code I have written in another question. It's a very simple piece of code that uses the library JAYROCK (you can download it free of charge here: http://jayrock.berlios.de/) that will read a JSON formatted string and will output the value of a parameter call "message" that is nested inside "error". Very basic stuff, but it might help you...
Dim cMessage As String = "{ ""error"" : { ""code"" : 500, " & _
"""message"" : ""Error Executing Task. " & _
"Error executing tool.""," & _
"""details"" : [] " & _
"}" & _
"}"
Dim objResponse As JsonObject
objResponse = CType(JsonConvert.Import(cMessage), JsonObject)
MsgBox( "Last response was: " + objResponse("error")("message") )
P.S.: In order to get this code working don't forget to import Jayrock.Json and Jayrock.Json.Conversion
Upvotes: 1