I want to create JSON , format is like
"header":
{
"b":"aaaa",
"c":"00",
"d":"zzzzz",
"e": "0"
},
"Body":
{
"g":
[
{
"h": "sss",
"i": "vvvv",
"j": "11111"
},
{
"h": "wwww",
"i": "ddddd",
"j": "0000"
},
{
"h": "eeeee",
"i": "asdf"
}
]
}
I want to create this JSON with the help of GSON.
The target JSON example in the original question is invalid. JSON must start with either ‘[‘ or ‘{‘. If the invalid JSON in the original question is wrapped in ‘{‘ and ‘}’, then it is a valid JSON object. (It’s easy to use http://jsonlint.com to validate JSON.) Assuming then that such a JSON object is the target data structure, following is an example of using a matching Java data structure with Gson to generate the JSON.