看看这个答案
典型的JSON如下所示
{
"name":"Ersin",
"surname":"Çetinkaya",
"age":"25",
"address":[{"city": "Bursa","country": "Türkiye","zipCode": "33444"}],
"phones": ["234234242","345345354"]
}
下面给出了用于创建上述JSON的Java代码
public JSONObject getValues()
{
JSONObject jsonobj=new JSONObject();
jsonobj.put("name","Ersin");
jsonobj.put("surname","Çetinkaya");
jsonobj.put("age","25");
JSONArray obj = new JSONArray();
HashMap rows=new HashMap();
rows.put("city","Bursa");
rows.put("country","Türkiye");
rows.put("zipCode","33444");
obj.put(rows);
jsonobj.put("address", obj);
JSONArray phobj = new JSONArray();
phobj.put("234234242");
phobj.put("345345354");
jsonobj.put("phones", phobj);
System.out.println(jsonobj.toString());
return jsonobj.toString();
}