我是 Java 中 JSON 的初学者http://json.org/java/
如何创建这样的 JSON 对象?
{
"RECORD": {
"customer_name": "ABC",
"customer_type": "music"
}
}
我是 Java 中 JSON 的初学者http://json.org/java/
如何创建这样的 JSON 对象?
{
"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);
您必须使“记录”成为 JSON 对象。这是一个例子:
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() );