-3

I want to know how I can get array element from json. I am using JSON.NET and already accessed the json file but can't figure out how I can parse nested array elements like nodes

JSON looks like that:

    {
      "language_code": "en",
      "platform": "web",
      "entry_data": {
        "ProfilePage": [
          {
            "user": {
              "country_block": null,
              "id": "3237234838",
              "full_name": "Lobi",
              "media": {
                "count": 217,
                "nodes": [
                  {
                    "code": "BLmDO3qAhtB",
                    "date": 1476558058,
                    "dimensions": {
                      "width": 1080,
                      "height": 720
                    },
                    "comments_disabled": false,
                    "comments": {
                      "count": 7
                    },
                    "caption": "Don't limit yourself by the ideas others put into your head! Try something different, think different, life different - simply be more than the day before!💧 Send some love 💙 Double tap! Like 3 posts!\n\nFollow 🌟 @pollux.starchild \nFollow 🌟 @pollux.starchild \nEveryday adventures: @sundownshots",
                    "likes": {
                      "count": 196
                    },
                    "owner": {
                      "id": "3237234838"
                    },
                    "thumbnail_src": "https://igcdn-photos-a-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/s640x640/sh0.08/e35/c180.0.720.720/14714497_117085415427760_4015602307872849920_n.jpg?ig_cache_key=MTM2MTc5MDE1MzI5ODk0Mjc4NQ%3D%3D.2.c",
                    "is_video": false,
                    "id": "1361790153298942785",
                    "display_src": "https://igcdn-photos-a-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/e35/14714497_117085415427760_4015602307872849920_n.jpg?ig_cache_key=MTM2MTc5MDE1MzI5ODk0Mjc4NQ%3D%3D.2"
                  },
                  {
                    "code": "BLjealpA06h",
                    "date": 1476471646,
                    "dimensions": {
                      "width": 1080,
                      "height": 720
                    },
                    "comments_disabled": false,
                    "comments": {
                      "count": 7
                    },
                    "caption": "New Beginnings are mostly scary initially, but they can take many pleasant unexpected turns!💧 Send some love 💙 Double tap! Like 3 posts!\n\nFollow 🌟 @pollux.starchild \nFollow 🌟 @pollux.starchild \nEveryday adventures: @sundownshots",
                    "likes": {
                      "count": 236
                    },
                    "owner": {
                      "id": "3237234838"
                    },
                    "thumbnail_src": "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/s640x640/sh0.08/e35/c180.0.720.720/14704974_741258352693470_5618822833925783552_n.jpg?ig_cache_key=MTM2MTA2NTI4MDkxNDI4MDA5Nw%3D%3D.2.c",
                    "is_video": false,
                    "id": "1361065280914280097",
                    "display_src": "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/e35/14704974_741258352693470_5618822833925783552_n.jpg?ig_cache_key=MTM2MTA2NTI4MDkxNDI4MDA5Nw%3D%3D.2"
                  },
                  {
                    "code": "BLg5w9QB3G4",
                    "date": 1476385322,
                    "dimensions": {
                      "width": 1080,
                      "height": 720
                    },
                    "comments_disabled": false,
                    "comments": {
                      "count": 4
                    },
                    "caption": "Be open to turn your life upside down for good!💧 Send some love 💙 Double tap! Like 3 posts!\n\nFollow 🌟 @pollux.starchild \nFollow 🌟 @pollux.starchild \nEveryday adventures: @sundownshots",
                    "likes": {
                      "count": 242
                    },
                    "owner": {
                      "id": "3237234838"
                    },
                    "thumbnail_src": "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/s640x640/sh0.08/e35/c180.0.720.720/14701136_922253567919054_2476090857082585088_n.jpg?ig_cache_key=MTM2MDM0MTE0MDQxOTA4MDYzMg%3D%3D.2.c",
                    "is_video": false,
                    "id": "1360341140419080632",
                    "display_src": "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/e35/14701136_922253567919054_2476090857082585088_n.jpg?ig_cache_key=MTM2MDM0MTE0MDQxOTA4MDYzMg%3D%3D.2"
                  },
                  {
                    "code": "BLeTTxGhv2O",
                    "date": 1476298051,
                    "dimensions": {
                      "width": 1080,
                      "height": 720
                    },
                    "comments_disabled": false,
                    "comments": {
                      "count": 7
                    },
                    "caption": "I bet you have something within you, you wish it was real. Fight for it and don't let the world out there change you! Only change to be better than yesterday.💧 Send some love 💙 Double tap! Like 3 posts!\n\nFollow 🌟 @pollux.starchild \nFollow 🌟 @pollux.starchild \nEveryday adventures: @sundownshots",
                    "likes": {
                      "count": 258
                    },
                    "owner": {
                      "id": "3237234838"
                    },
                    "thumbnail_src": "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/s640x640/sh0.08/e35/c180.0.720.720/14711876_767095436764222_3395160437623357440_n.jpg?ig_cache_key=MTM1OTYwOTA1ODc4OTA5Njg0Ng%3D%3D.2.c",
                    "is_video": false,
                    "id": "1359609058789096846",
                    "display_src": "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/e35/14711876_767095436764222_3395160437623357440_n.jpg?ig_cache_key=MTM1OTYwOTA1ODc4OTA5Njg0Ng%3D%3D.2"
                  },
                  {
                    "code": "BLbvkEnAybC",
                    "date": 1476212202,
                    "dimensions": {
                      "width": 1080,
                      "height": 720
                    },
                    "comments_disabled": false,
                    "comments": {
                      "count": 11
                    },
                    "caption": "It's not about weakness but emotional exclusiveness.💧 Send some love 💙 Double tap! Like 3 posts!\n\nFollow 🌟 @pollux.starchild \nFollow 🌟 @pollux.starchild \nEveryday adventures: @sundownshots",
                    "likes": {
                      "count": 248
                    },
                    "owner": {
                      "id": "3237234838"
                    },
                    "thumbnail_src": "https://igcdn-photos-f-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/s640x640/sh0.08/e35/c180.0.720.720/14540408_1108129005944901_8031323788203261952_n.jpg?ig_cache_key=MTM1ODg4ODg5OTYxOTAwNjE0Ng%3D%3D.2.c",
                    "is_video": false,
                    "id": "1358888899619006146",
                    "display_src": "https://igcdn-photos-f-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/e35/14540408_1108129005944901_8031323788203261952_n.jpg?ig_cache_key=MTM1ODg4ODg5OTYxOTAwNjE0Ng%3D%3D.2"
                  },
                  {
                    "code": "BLMSCq2hSFD",
                    "date": 1475693407,
                    "dimensions": {
                      "width": 1080,
                      "height": 608
                    },
                    "comments_disabled": false,
                    "comments": {
                      "count": 12
                    },
                    "caption": "Hold on to the people who care for you! Look for actions, not for words...💧 Send some love 💙 Double tap! Like 3 posts!\n\nFollow 🌟 @pollux.starchild \nFollow 🌟 @pollux.starchild \nEveryday adventures: @sundownshots",
                    "likes": {
                      "count": 277
                    },
                    "owner": {
                      "id": "3237234838"
                    },
                    "thumbnail_src": "https://igcdn-photos-b-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/e35/c236.0.608.608/14449294_311761075847057_5957362236484747264_n.jpg?ig_cache_key=MTM1NDUzNjkzNjIxOTY4MTA5MQ%3D%3D.2.c",
                    "is_video": false,
                    "id": "1354536936219681091",
                    "display_src": "https://igcdn-photos-b-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-15/e35/14449294_311761075847057_5957362236484747264_n.jpg?ig_cache_key=MTM1NDUzNjkzNjIxOTY4MTA5MQ%3D%3D.2"
                  }
                ]
              },
              "is_verified": false,
              "external_url": null
            }
          }
        ]
      }
    }


  JObject jResults = JObject.Parse(fullstring);
                var language_code = jResults["language_code"].Value<string>();

Thanks in advance!

2
  • 1
    Possible duplicate of parsing nested json with json.net Commented Oct 16, 2016 at 22:00
  • Read the documentation, instead of down-voting those trying to tell you to do so. This is why I hate SO. People that doesn't make an effort to learn, just wants answers. Commented Oct 16, 2016 at 22:17

1 Answer 1

1

if it's array, then you need to use index to identify which element you need in this array

For example:

var userId = jResults["entry_data"]["ProfilePage"][0]["user"]["id"].ToString()
Sign up to request clarification or add additional context in comments.

Comments

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.