我正在尝试使用这种精确的 JSON 语法,但无法使用:
{
"sun":"yellow",
"vegetables":[{
"apple":"red",
"banana":"yellow",
"melon":"orange"
}]
}
我能得到的最接近的是:
{
"sun":"yellow",
"vegetables":["{
"apple":"red",
"banana":"yellow",
"melon":"orange"
"]}
}
这就是我正在做的事情:
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);
我想不通,我错过了什么吗?