Converting JSON to Array in VB.NET

后端 未结 2 648
小鲜肉
小鲜肉 2020-12-21 04:23

I have this code

Dim x As String
x = \"{\'books\':[{\'title\':\'HarryPotter\',\'pages\':\'134\'}]}\"

what i want to do is to convert it int

相关标签:
2条回答
  • 2020-12-21 04:52

    @Professor Haseeb Maybe you forget to Add the following to @Dominic Kexel solution:

    Imports Newtonsoft.Json
    

    Or use:

    Dim result = Newtonsoft.Json.JsonConvert.DeserializeObject(x)
    
    0 讨论(0)
  • 2020-12-21 05:10

    Your string x does not contain an array, but a single JSON object.

    Just use a JSON library like Json.NET to parse your string:

    Dim x = "{'books':[{'title':'HarryPotter','pages':'134'}]}"
    
    Dim result = JsonConvert.DeserializeObject(x)
    Console.WriteLine(result("books")(0)("title") & " - " & result("books")(0)("pages"))
    

    Output:

    HarryPotter - 134

    0 讨论(0)
提交回复
热议问题