try {
JSONObject parent = new JSONObject();
JSONObject jsonObject = new JSONObject();
jsonObject.put("name",Person_Name);
jsonObject.put("number", Mobile_Number);
jsonObject.put("query",Person_Query);
jsonObject.put("action",Action);
parent.put("result", jsonObject);
} catch (JSONException e) {
e.printStackTrace();
}
输出-
{
"result": {
"name":"Person_Name",
"number":"Mobile_Number",
"query":"Person_Query",
"action":"Action"
}
}
如果要添加 json 数组:
JSONArray jsonArray = new JSONArray();
jsonArray.put("list1");
jsonArray.put("list2");
jsonObject.put("mylist", jsonArray);
output: {
"mylist":[ "list1",
"list2"]
}