在 VB.Net 中访问 Json 结构

Access Json Structure in VB.Net

我刚刚开始在我的程序中解析 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 = ""

所以我无法在列表中保存 children。您能告诉我如何使用 vb.net 访问 "Linked" child 下 json 结构中的 href 元素吗?

如果您能提供一个示例来访问 Json Structure with vb.net 代码中的以下行,我将非常感谢。

href": "http://blabla/bla/bla/pot/pots/5a267e98-0a12-4110-bac3-575439cb6097"

ToList 方法是 extension methodIEnumerable(Of T) 接口。它由 System.Core.dll 库在 System.Linq 命名空间中定义。因此,除非您引用该库并导入该命名空间,否则您将不会在任何可枚举对象上看到 ToList 方法。 ToList 不是由可枚举类型本身定义的方法。它是一种由该库自动附加到类型接口的方法,但仅当引用扩展它的库并导入命名空间时。

LINQ 及其所有扩展方法都已添加到 .NET Framework 3.5 版本中,因此如果您的项目面向 3.0 或更早版本,您将无法访问其中任何一个.