0
String jsonResponse=Utils.getGsonInstance().toJson(Object);
jsonResponse zurück:einen Schlüsselwert In den JSON-String von GSON.toJSON erzeugt
[
{
"Key":"1",
"Code": "11",
},
{
"key":"2",
"code": "22",
}
]
Endergebnis ich suche ist dieses JSON-String in einem anderen Schlüssel Z. B. wickeln
{
"MainObj":
[
{
"Key":"1",
"Code": "11",
},
{
"key":"2",
"code": "22",
}
]
}
Gibt es eine Möglichkeit, die ich mit GSON Api erreichen kann?
Ich versuchte ::
JSONObject jsonObject = new JSONObject();
jsonObject.put("MainObj",jsonResponse);
Output Ich erhalte ist:
{"MainObj": "[{\"Key\":\"1",\"Code\":\"11\"}, {\"Key\":\"2",\"Code\":\"22\"}]"}
'JSONObject JsonObject = new JSONObject(); jsonObject.put ("MainObj", jsonResponse.get (i)); ' –
Ich weiß nicht, ob es Ihre Anforderungen erfüllen. Aber so machen wir das bei Android, also habe ich das als Kommentar hinzugefügt. –