# JSON get Array in Array [closed]

I need to generate JSON array in array data. I am able to get data from first array, however not able to get data from child array.

For example :-

[ { "id":"2012" "month": [ { "1": "Jan 2012"}, { "2": "Feb"} ] }, { "id":"2011" "month": [ { "1": "Jan 2011"}, { "2": "Feb"} ] } ]

I know how to call data from first array but stuck to get data from 2nd array, namely: month's data.

Please suggest me how I can get data from array in array

-
I think this belongs on Stack Overflow. Also, please show us what you have tried. –  S.L. Barth Nov 21 '12 at 6:09

## closed as off topic by Glenn Rogers, Jeff Mercado, Paul, sepp2kNov 23 '12 at 15:09

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

First - your example is wrong. You should put comma after each id' value.

var jsonObject = {
"id": "2012",
"month": [
{"1": "Jan 2012"},
{"2": "Feb"}
]
}, {
"id": "2011",
"month": [
{"1": "Jan 2011"},
{"2": "Feb"}
]
}


And get data from json, like this:

var month = jsonObject[0].month[1];
var monthName = month["2"];


Another way - rename the keys in child array, for example {"m1": "Jan 2011"} and so on. And than you can get data form json object in a line ...

var monthName = json[0].month[1].m2;


Good luck.

-
you missed the square brackets for outer array, other than that answer is correct –  almaz Nov 21 '12 at 11:06