1

I have just started the parse the Json structure in my program. My ServerResponse is look like as follows.

I dont know how to paste the json structure here. Therefore i just copy and paste the structure here.

{
"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
        },

NOW here is my VB.NET code:

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 = ""

So that i cannot save the children in the lists. Can you please tell me that how can I access the href elements in the json structure under "Linked" child with vb.net.

I shall be very thankful to you if you provide me one example to access the following line from Json Structure with vb.net code.

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

7
  • What error does it show on that line? In all likelihood, you may not need the () if Children is a property, not a method. I haven't used JObject in quite some time (I find Json.Net far more useful/flexible). Commented Mar 24, 2015 at 13:16
  • i have also tried this but no suceess.......Dim data As List(Of JToken) = ser.Children().ToList.... Visual Studio Shows me error that "ToList is not a member of Newtonsoft.Json.Linq.JToken" Commented Mar 24, 2015 at 13:21
  • Do you have the System.Linq namespace imported? Commented Mar 24, 2015 at 13:21
  • I have added follwoing: <<BR>> Imports System.IO Imports System.Net Imports System.Text Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq Imports System.Collections.Generic Commented Mar 24, 2015 at 13:24
  • That doesn't answer my question. Do you have Imports System.Linq? Commented Mar 24, 2015 at 13:26

1 Answer 1

1

The ToList method is an extension method to the IEnumerable(Of T) interface. It is defined in the System.Linq namespace by the System.Core.dll library. Therefore, unless you reference that library and import that namespace, you will not see the ToList method on any enumerable object. ToList is not a method that is defined by the enumerable types, themselves. It is a method that is automatically appended to the type's interface by that library, but only when the library that extends it is referenced and the namespace imported.

LINQ, along with all of its extension methods, were added in the 3.5 version of the .NET Framework, so you won't have access to any of it if your project is targeting 3.0 or earlier.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much Steven Doggart for quick help. I am very thankful to you. Now i can Access ToList for children. Now i develop program for accessing the href vaule in json. Thanks again dear...see u on next time :)
now i cannot Access the "Pemash" items. :(. i try to post my code here. Maybe then you can help me.
I suggest posting it as a new question rather than adding here. I may not be able to help you because I don't know anything about that JSON library in particular. If you ask it as a new question, people will be more likely to see it and help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.