Java JSON键的多个值
我是Java中JSON的初学者 如何创建这样的JSON对象Java JSON键的多个值,java,json,Java,Json,我是Java中JSON的初学者 如何创建这样的JSON对象 { "RECORD": { "customer_name": "ABC", "customer_type": "music" } } 试着这样做: JSONObject jsonObject = new JSONObject(); jsonObject.put("customer_name", "ABC"); jsonObject.put("customer_ty
{
"RECORD": {
"customer_name": "ABC",
"customer_type": "music"
}
}
试着这样做:
JSONObject jsonObject = new JSONObject();
jsonObject.put("customer_name", "ABC");
jsonObject.put("customer_type", "music");
JSONObject jsonObject_rec = new JSONObject();
jsonObject_rec.put("RECORD", jsonObject);
System.out.println(jsonObject_rec);
您必须使“记录”成为JSONobject。这是一个例子:
JSONObject json = new JSONObject();
// Add a JSON Object
JSONObject Record = new JSONObject();
Record.put( "customer_name", "ABC");
Record.put( "customer_type", "music");
json.put( "RECORD", Record);
// P toString()
System.out.println( "JSON: " + json.toString() );