how to parse a jsonObject using JsonArray that have dynamic id's in start as integer
sorry but i amm not a player of Json it's my first time. so please tell me how can i parse a the following rsponse using jsonArray. As JsonObject need an string to return the the JsonArray but in my case i have dynamic Keys as integer and i have to parse it as it is....
{
"1":{
"services":{
"2":{
"service":{
"title":"test 1 service",
"defaultDuration":"60",
"brief":"testing brief ...",
"classSize":"6",
}
},
"3":{
"service":{
"title":"test service 2",
"defaultDuration":"60",
"brief":"testing 2 brief... ",
"classSize":"1",
}
},
"organisation":{
"title":"First organization",
"url":"http:\/\/test.com\/main",
"address":"First Floor ",
"suburb":"Arma",
"postcode":"31435",
"state":"VIC",
"country":"AU"
}
},
"643":{
"services":{
"1325":{
"service":{
"title":"test 1 service",
"defaultDuration":"90",
"brief":"test 1 sevice brief,
"classSize":"1",
}
},
"1523":{
"service":{
"title":"test 2 service",
"defaultDuration":"90",
"brief":"test 2 brief.",
"classSize":"1",
}
},
"organisation":{
"title":"Second orginization",
"url":"http:\/\/test.com\/main2",
"address":"18 Street"开发者_开发知识库,
"suburb":"South ",
"postcode":"1241",
"state":"Teststate",
"country":"US"
}
}
}
Your real problem is that the JSON you are parsing is NOT an array. It is an object (a dictionary) whose keys are numbers.
If you really need it to be an array, you will need to parse it as a JsonObject and build the array yourself by iterating over the object's keys, etcetera.
I would also add that this is not a good idea, if the sample you have provided is indicative. The resulting array will be sparse; i.e. there will be lots of "holes" where there is no entry for a given index. This could waste a lot memory ... depending on the actual keys.
精彩评论