使用JAVA创建JSONObject

时间:2015-12-11 20:35:14

标签: java json

我需要使用JAVA创建JSONObject。有人能帮我吗? JSON应如下所示:

{
  "text":[
    "Java",
    "JavaC"
  ],
  "metaData":{
    "fileName":"javaLangSpec.txt",
    "fileSize":"900KB",
    "fileCreationDate":"January 23, 1996 at 12: 52PM"
  }
}

1 个答案:

答案 0 :(得分:0)

这很简单:

 String jsonString = "{\n" +
                "  \"text\":[\n" +
                "    \"Java\",\n" +
                "    \"JavaC\"\n" +
                "  ],\n" +
                "  \"metaData\":{\n" +
                "    \"fileName\":\"javaLangSpec.txt\",\n" +
                "    \"fileSize\":\"900KB\",\n" +
                "    \"fileCreationDate\":\"January 23, 1996 at 12: 52PM\"\n" +
                "  }\n" +
                "}";

        JSONObject jsonObject = new JSONObject(jsonString);