REST and JSON - converting string to JSON array

前端 未结 3 737
醉梦人生
醉梦人生 2021-01-19 03:53

I\'m new to JSON and REST. I\'m working with a server that returns strings like these:

[{\"username\":\"Hello\",\"email\":\"hello@email.com\",\"credits\":\"1         


        
3条回答
  •  情话喂你
    2021-01-19 04:00

    • use GSON to format the string as JsonArray
    • then traverse the JsonArray to get the values

    the code sample

    String json = "[{\"username\":\"Hello\",\"email\":\"hello@email.com\",\"credits\":\"100\",\"twitter_username\":\"\"},{\"username\":\"Goodbye\",\"email\":\"goodbye@email.com\",\"credits\":\"0\",\"twitter_username\":\"\"}]";
    JsonArray jArray = new JsonParser().parse(json).getAsJsonArray();
    for (int i=0;i

提交回复
热议问题