Wednesday 8 May 2013

Get Data from JSONArray inside an array using JQuery

The service will return the JSONArray inside an Array, that time we would need to use the following method to get a particular data from the service response.

The JSONArray inside an array format service response will looks like as follows,

var response= {
    "Name":
     [
        [{"Key": "A", "Value": "Sample1" }],
        [{ "Key": "A","Value": "Sample2"}],
        [{"Key": "A","Value": "Sample3" }],
        [{"Key": "A","Value": "Sample4" }]
    ],
    "Title": "Office"
}


Now, we want to get the data as "Value" from the above response.

We will use the the following jquery, we would get the output.

$.each( response.Name, function( index, result ) {
  alert( index + ": " + result[0].Value );
  console.log( index + ": " + result[0].Value );
});

No comments:

Post a Comment