Quiero crear un objeto JSON usando String.
Ejemplo: JSON {"test1":"value1","test2":{"id":0,"name":"testName"}}
Para crear el JSON anterior, estoy usando esto.
String message;
JSONObject json = new JSONObject();
json.put("test1", "value1");
JSONObject jsonObj = new JSONObject();
jsonObj.put("id", 0);
jsonObj.put("name", "testName");
json.put("test2", jsonObj);
message = json.toString();
System.out.println(message);
Quiero saber cómo puedo crear un JSON que tenga JSON Array.
A continuación se muestra el JSON de muestra.
{
"name": "student",
"stu": {
"id": 0,
"batch": "batch@"
},
"course": [
{
"information": "test",
"id": "3",
"name": "course1"
}
],
"studentAddress": [
{
"additionalinfo": "test info",
"Address": [
{
"H.No": "1243",
"Name": "Temp Address",
"locality": "Temp locality",
"id":33
},
{
"H.No": "1243",
"Name": "Temp Address",
"locality": "Temp locality",
"id":33
},
{
"H.No": "1243",
"Name": "Temp Address",
"locality": "Temp locality",
"id":36
}
],
"verified": true,
}
]
}
Gracias.
JSONObject
una cadena?