【发布时间】:2015-03-24 13:13:39
【问题描述】:
我刚刚开始在我的程序中解析 Json 结构。 我的 ServerResponse 如下所示。
我不知道如何在此处粘贴 json 结构。因此,我只是在此处复制并粘贴结构。
{
"pot_searches": [
{
"id": 24,
"links": {
"results": [
{
"type": "pot_search_results",
"id": 191
},
{
"type": "pot_search_results",
"id": 192
},
{
"type": "pot_search_results",
"id": 193
},
{
"type": "pot_search_results",
"id": 194
},
{
"type": "pot_search_results",
"id": 195
},
{
"type": "pot_search_results",
"id": 196
},
{
"type": "pot_search_results",
"id": 197
},
{
"type": "pot_search_results",
"id": 198
},
{
"type": "pot_search_results",
"id": 199
},
{
"type": "pot_search_results",
"id": 200
}
],
"query_tree": null
},
"description": "hello example",
"query_text": "Heat",
"limit": 10,
"error": null,
"created_by": null,
"href": "http://blabla/bla/bla/pot/searches/24"
},
{
"id": 25,
"links": {
"results": [
{
"type": "pot_search_results",
"id": 201
},
{
"type": "pot_search_results",
"id": 202
},
{
"type": "pot_search_results",
"id": 203
},
{
"type": "pot_search_results",
"id": 204
},
{
"type": "pot_search_results",
"id": 205
},
{
"type": "pot_search_results",
"id": 206
},
{
"type": "pot_search_results",
"id": 207
},
{
"type": "pot_search_results",
"id": 208
},
{
"type": "pot_search_results",
"id": 209
},
{
"type": "pot_search_results",
"id": 210
}
],
"query_tree": null
},
"description": "hello example",
"query_text": "Heat",
"limit": 10,
"error": null,
"created_by": null,
"href": "http://blabla/bla/bla/pot/searches/25"
}
],
"linked": {
"pot_search_results": [
{
"links": {
"Pemash": {
"type": "pot_browse_contents",
"href": "http://blabla/bla/bla/pot/pots/5a267e98-0a12-4110-bac3-575439cb6097",
"id": "5a267e98-0a12-4110-bac3-575439cb6097"
},
"found_terms": [
{
"type": "pot_search_found_terms",
"id": 780
},
{
"type": "pot_search_found_terms",
"id": 781
},
{
"type": "pot_search_found_terms",
"id": 782
},
{
"type": "pot_search_found_terms",
"id": 783
},
{
"type": "pot_search_found_terms",
"id": 784
}
]
},
"id": 191,
"score": 13.765055790063306
},
{
"links": {
"Pemash": {
"type": "pot_browse_contents",
"href": "http://blabla/bla/bla/pot/pots/5a267e98-0a12-4110-bac3-575439cb6097",
"id": "5a267e98-0a12-4110-bac3-575439cb6097"
},
"found_terms": [
{
"type": "pot_search_found_terms",
"id": 785
},
{
"type": "pot_search_found_terms",
"id": 786
},
{
"type": "pot_search_found_terms",
"id": 787
},
{
"type": "pot_search_found_terms",
"id": 788
}
]
},
"id": 192,
"score": 10.669084946432259
},
{
"links": {
"Pemash": {
"type": "pot_browse_contents",
"href": "http://blabla/bla/bla/pot/pots/5a267e98-0a12-4110-bac3-575439cb6097",
"id": "5a267e98-0a12-4110-bac3-575439cb6097"
},
"found_terms": [
{
"type": "pot_search_found_terms",
"id": 789
},
{
"type": "pot_search_found_terms",
"id": 790
},
{
"type": "pot_search_found_terms",
"id": 791
},
{
"type": "pot_search_found_terms",
"id": 792
}
]
},
"id": 193,
"score": 10.669084946432259
},
现在这是我的 VB.NET 代码:
Dim json As String = responseFromServer
Dim ser As JObject = JObject.Parse(json)
Dim data As List(Of JToken) = ser.Children().tolist() 'VisualStudio shows me error here that ToList is not a member of Newtonsoft.Json.Linq.JToken
Dim output As String = ""
这样我就无法将孩子保存在列表中。您能否告诉我如何使用 vb.net 访问“链接”子项下 json 结构中的 href 元素。
如果您提供一个示例,让我使用 vb.net 代码从 Json Structure 访问以下行,我将非常感谢您。
href": "http://blabla/bla/bla/pot/pots/5a267e98-0a12-4110-bac3-575439cb6097"
【问题讨论】:
-
那一行显示什么错误?如果
Children是一个属性,而不是一个方法,那么您很可能不需要()。我已经有一段时间没有使用 JObject(我发现 Json.Net 更有用/更灵活)。 -
我也试过这个但没有成功.......将数据作为 List(Of JToken) = ser.Children().ToList.... Visual Studio 显示错误“ ToList 不是 Newtonsoft.Json.Linq.JToken 的成员"
-
您是否导入了
System.Linq命名空间? -
我添加了以下内容:> Imports System.IO Imports System.Net Imports System.Text Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq Imports System.Collections.Generic
-
这不能回答我的问题。你有
Imports System.Linq吗?