For example if I had a string of 3 json objects:
{"id":"1","status":"SENT","sent_at":"2020-02-25T11:00:02+00:00"},{"id":"2","status":"SENT","sent_at":"2020-02-18T11:00:02+00:00"},{"id":"3","status":"SENT","sent_at":"2020-02-11T11:00:03+00:00"}
(above example is one long string)
How can I store all above information in an Array of individual json objects? I'm using Java!
Convert to valid json by wrapping in [...]
, ie (formatted for readability only):
[
{"id":"1","status":"SENT","sent_at":"2020-02-25T11:00:02+00:00"},
{"id":"2","status":"SENT","sent_at":"2020-02-18T11:00:02+00:00"},
{"id":"3","status":"SENT","sent_at":"2020-02-11T11:00:03+00:00"}
]
Parse using your favorite library, eg
List<Object> objects = new ObjectMapper().readValue(str, List.class);
If you deperately need an array (not recommended):
Object[] array = objects.toArray();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.