开发者

Json in VB.net version

开发者 https://www.devze.com 2022-12-10 22:06 出处:网络
I have seen there are many exam开发者_运维问答ples in C# version. Same also as DataContractJsonSerializer class in MSDN. Anyone please help me on VB.net version?Here\'s the same source code I have wri

I have seen there are many exam开发者_运维问答ples in C# version. Same also as DataContractJsonSerializer class in MSDN. Anyone please help me on VB.net version?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号