gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:57:48 25 4
gpt4 key购买 nike

我有这个代码

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

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

最佳答案

您的字符串 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"))

输出:

HarryPotter - 134

关于vb.net - 在 VB.NET 中将 JSON 转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23079275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com