如何解析使用JsonArray具有动态的ID在开始为整数一个JSONObject [英] how to parse a jsonObject using JsonArray that have dynamic id's in start as integer
问题描述
抱歉,但我不AMM的JSON的球员这是我的第一次。所以请告诉我如何可以解析使用jsonArray一个下列rsponse。作为JSONObject的需要一个字符串返回的JsonArray但对我来说,我有动态密钥整数和我有解析它,因为它是....
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"
}
}
}
推荐答案
您真正的问题是,你解析JSON是不是数组。它是一个对象(字典),它的键是数字。
Your real problem is that the JSON you are parsing is NOT an array. It is an object (a dictionary) whose keys are numbers.
如果你真的需要它是一个数组,则需要通过遍历对象的关键,等等解析它作为一个JSONObject并建立自己的数组。
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.
这篇关于如何解析使用JsonArray具有动态的ID在开始为整数一个JSONObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!