I'm using this code:
JSONObject jO = new JSONObject();
try {
jO.put("item1", true);
jO.put("item2", value2);
jO.put("item3", value3);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String json = null;
try {
json = jO.toString(4);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
File jsonFile = new File(nContext.getDir("json", 0), "dashboard.json");
//simple utility method to write the json file
Utils.writeToFile(jsonFile, json);
to have this result:
{
"item3": "12345",
"item2": "abcde",
"item1": true
}
What I want to achieve, on the next run of the same piece of code, is to end with something like:
{
"pass1": {
"item3": "12345",
"item2": "abcde",
"item1": true
},
"pass2": {
"item3": "67890",
"item2": "zxcvb",
"item1": true
}
}
Or maybe is it better to have this?
{
"pass1": [
{
"item3": "12345",
"item2": "abcde",
"item1": true
}
],
"pass2": [
{
"item3": "67890",
"item2": "zxcvb",
"item1": true
}
]
}
I know this implies a change in the code to include a "nested" object/array.
Which one is better, considering that I'll have to parse the JSON to build a ListView?
Any ideas?