Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JSON键的多个值_Java_Json - Fatal编程技术网

Java 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

我是Java中JSON的初学者

如何创建这样的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);
您必须使“记录”成为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() );