JSON密钥的多个值

时间:2013-10-31 05:15:05

标签: java json

我是Java {J}的初学者http://json.org/java/

如何创建这样的JSON对象?

{
    "RECORD": {
        "customer_name": "ABC",
        "customer_type": "music"
    }
}

1 个答案:

答案 0 :(得分:1)

您必须将“RECORD”设为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() );