How do I get the value of an individual & ldquo; Row & rdquo; In my json in my xamarincode?

advertisements

I am currently working on a code but i get the error "Cannot access child value on Newtonsoft.Json.Linq.JValue" when I try to get a value from my json on a patricular "row".

I gather the data as a JObject and via httplink so I get the data just fine. But I am having trouble gathering just one of the selected row i chose. This is the code:

async void loadPhot ()
    {
        var getItems = await parse.getPhotos ();

        foreach (var moreitems in getItems["results"])
        {
            var Pic = "";

            Pic = (string)moreitems["Image"][0]; //error here. trying to get the first data in the json

            picture.Source = Pic; //picture is my x:name of my image in xaml.

        }

    }

The json looks like this:

{

"results": [
    {

        "Image": "url"
    },

    {

        "Image": "url2"
    }
          ]

 }


Just replace

Pic = (string)moreitems["Image"][0]; //error here. trying to get the first data in the json

with

Pic = (string)moreitems["Image"]; //error here. trying to get the first data in the json

To get an item at a specific row do:

var rows = getItems["results"]; 

int desiredRow = 0;

var itemAtRow = rows.ElementAt(desiredRow);

var imageAtRow = itemAtRow["Image"];