访问VB.Net中的Json结构



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

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

LINQ及其所有扩展方法都添加在.NET Framework的3.5版本中,因此如果您的项目目标是3.0或更早版本,则您将无法访问其中的任何方法。

相关内容

  • 没有找到相关文章

最新更新