在 VB.NET 中将 JSON 转换为数组 [英] Converting JSON to Array in VB.NET
本文介绍了在 VB.NET 中将 JSON 转换为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码
Dim x As String
x = "{'books':[{'title':'HarryPotter','pages':'134'}]}"
我想要做的是使用 json_decode(x,TRUE or FALSE)
函数将它转换成数组,就像我们在 PHP 中所做的那样
what i want to do is to convert it into array like we do in PHP using the json_decode(x,TRUE or FALSE)
function
推荐答案
您的字符串 x
不包含数组,而是包含单个 JSON 对象.
Your string x
does not contain an array, but a single JSON object.
只需使用像 Json.NET
这样的 JSON 库来解析您的字符串:
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"))
输出:
哈利波特 - 134
这篇关于在 VB.NET 中将 JSON 转换为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文