在 VB.net 中获取 JSON 对象的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20924190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get value of JSON object in VB.net
提问by Lars Holdgaard
I have the following code I would use in C#:
我有以下代码将在 C# 中使用:
var tokenJson = JsonConvert.SerializeObject(tokenJsonString);
var jsonResult = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(jsonString);
var firstItem = jsonResult["data"][0];
However, I have a VB.NET client, and I have no idea how to translate it. I have tried different online tools without a result.
但是,我有一个 VB.NET 客户端,我不知道如何翻译它。我尝试了不同的在线工具,但没有结果。
I have a JSON response like this:
我有一个像这样的 JSON 响应:
"{\"token\":\"1edd6006-678a-4e6a-ab65-4fa60efa8632\"}"
And I just want the value of the token. In VB.NET ;)
我只想要令牌的价值。在 VB.NET 中;)
回答by Luc Morin
Try this:
尝试这个:
Dim tokenJson = JsonConvert.SerializeObject(tokenJsonString)
Dim jsonResult = JsonConvert.DeserializeObject(Of Dictionary(Of String, Object))(jsonString)
Dim firstItem = jsonResult.Item("data").Item(0)
Cheers
干杯
回答by Miguel Vale
Chosen awnser gives you the row { "token":"1edd6006-678a-4e6a-ab65-4fa60efa8632" } Had the same problem and to get exactly the value of the token you can do:
选择的 awnser 为您提供了行 { "token":"1edd6006-678a-4e6a-ab65-4fa60efa8632" } 遇到了同样的问题,要准确获取令牌的值,您可以这样做:
Dim firstItem = jsonResult.Item("data").Item(0).Value(Of String)("token")
Outputs: "1edd6006-678a-4e6a-ab65-4fa60efa8632"
输出:“1edd6006-678a-4e6a-ab65-4fa60efa8632”
Hope it helps
希望能帮助到你

