I am a newbie to android and I have a JSON file with dynamic key like this:
{
"x": {
"a": {
"1": [1,2,3,4],
"2": [1,2,3,4]
},
"b": {
"1": [1,2,3,4],
"2": [1,2,3,4]
}
},
"y": {
"a": {
"1": [1,2,3,4],
"2": [1,2,3,4]
},
"b": {
"1": [1,2,3,4],
"2": [1,2,3,4]
}
},
"z": {
"a": {
"1": [1,2,3,4],
"2": [1,2,3,4]
},
"b": {
"1": [1,2,3,4],
"2": [1,2,3,4]
}
}
}
I parsed it successfully by JSONObject but I have to loop by keys Iterator on x, y, z. For each time, I have to loop on a, b and the same for "1" and "2". I think it's not a good solution. I created models for them like this:
Class XYZ {
private String name; // "x", "y", "z" value
private ArrayList<ABC> abcList;
}
Class ABC {
private String name; // "a", "b", "c"
private ArrayList<Item> itemList;
}
Class Item{
private String ID; // "1", "2"
private int[] valueArray;
}
Can anyone help me to parse this json by Gson, I think it looks more professional :D. Thank you so much