在VB.NET中将JSON转换为数组

Pro*_*eeb 4 vb.net

我有这个代码

Dim x As String
x = "{'books':[{'title':'HarryPotter','pages':'134'}]}"
Run Code Online (Sandbox Code Playgroud)

我想要做的是将它转换为数组,就像我们在PHP中使用该json_decode(x,TRUE or FALSE)函数一样

slo*_*oth 7

您的字符串x不包含数组,而是包含单个JSON对象.

只需使用像Json.NET解析字符串的JSON库:

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

Dim result = JsonConvert.DeserializeObject(x)
Console.WriteLine(result("books")(0)("title") & " - " & result("books")(0)("pages"))
Run Code Online (Sandbox Code Playgroud)

输出:

哈利波特 - 134