Confused in JSON Array

Hi Friends,

I want help for JSON Object.

In my code I have following data in JSON

{
“result”:[{
“title”:“yyyy”,
“desc”:“xxxx”
},{
“title”:“yyyy”,
“desc”:“xxxx”
}]
}

Now in above example i have two results. Lets consider of there is just one result, So how the output should be ? The first one or second one. Please help me out…:frowning:

{
“result”:[{
“title”:“yyyy”,
“desc”:“xxxx”
}]
}

OR

{
“result”:{
“title”:“yyyy”,
“desc”:“xxxx”
}
}

Rather than having the same data in both of the array elements it should be something like this:


var myObj = {"result" : [{"title" : "title1", "desc" : "desc1"},{"title" : "title2", "desc" : "desc2"}]};
alert(myObj.result[0].title);
alert(myObj.result[1].title);

Hope you will understand how the json variable/element/array can be accessed.

This is sample data, So i have used same data in both objects…
The results data will be different in both array.
I m just confused on that
If i get single element then i should use square bracket or not…

See here for more details in accessing and creating JSON objects with array.
http://www.json.org/js.html