简体   繁体   中英

Server response JSON string list parse

I'm making HTTP requests to a server and I my response comes back as a string in the following format:

[
  {
    "key1": "val1"
  },
  {
    "key2": "val2"
  }
]

So it is given back as a string list and each 'element' in the string is a JSON string.

What is the most effective way to retrieve each json?

I'd strip the square brackets on the first and last and then do a string.split({regex}) to get a string array but I'm not sure if that's the best way?

But the regex might get quite convoluted as I can't just split on "," as some key value pairings could have a list as values which will also include "," so determining when the first json actually starts might be tricky.

Are there any libraries that can help?

Thanks

Found the answer,

JsonArray root = new JsonParser().parse(response).getAsJsonArray();

Cheers

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM