Reputation: 33
I am a beginner on JSON in Java http://json.org/java/
How can I create a JSON object like this?
{
"RECORD": {
"customer_name": "ABC",
"customer_type": "music"
}
}
Upvotes: 2
Views: 4365
Reputation: 87
You have to make "RECORD" an JSONobject. This is an example:
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() );
Upvotes: 1
Reputation: 5149
Try like this:
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);
Upvotes: 2