I am trying to have this exact JSON syntax but can't get to it:
{
"sun":"yellow",
"vegetables":[{
"apple":"red",
"banana":"yellow",
"melon":"orange"
}]
}
The closest I can get is:
{
"sun":"yellow",
"vegetables":["{
"apple":"red",
"banana":"yellow",
"melon":"orange"
"]}
}
This is what I am doing:
JSONObject json = new JSONObject();
json.put("sun","yellow");
ArrayList<HashMap<String,Object>> test = new ArrayList<HashMap<String,Object>>();
HashMap<String,Object> params = new HashMap<String, Object>();
params.put("apple","red");
params.put("banana","yellow");
params.put("melon","orange");
test.add(params);
json.put("fruits",test);
I can't figure it out, am I missing something?