我刚开始解析程序中的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访问“Linked”子项下的json结构中的href元素。
如果您提供一个使用vb.net代码从Json Structure访问以下行的示例,我将非常感谢您。
href“:”http://blabla/bla/bla/pot/pots/5a267e98-0a12-4110-bac3-575439cb6097“
答案 0 :(得分:1)
ToList
方法是IEnumerable(Of T)
接口的extension method。它由 System.Core.dll 库在System.Linq
命名空间中定义。因此,除非您引用该库并导入该命名空间,否则您将无法在任何可枚举对象上看到ToList
方法。 ToList
不是由可枚举类型本身定义的方法。它是一个由该库自动附加到类型接口的方法,但仅在引用扩展它的库并导入命名空间时才会附加。
LINQ及其所有扩展方法已添加到.NET Framework的3.5版本中,因此如果您的项目定位到3.0或更早版本,则无法访问任何扩展方法。 / p>