REST and JSON - converting string to JSON array

前端 未结 3 765
醉梦人生
醉梦人生 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:22

    I am using gson library to manipulate json. You can download gson from here. It is a very good library to handle json. Create json parser first, it will parse the json string:

    JsonParser parser = new JsonParser();
    

    now initialize an empty json array

    JsonArray jArray = new JsonArray();
    

    Now use the parser to create json array

    jArray = parser.parse(outputString).getAsJsonArray();
    

提交回复
热议问题