REST and JSON - converting string to JSON array

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

    I have used org.json.simple.JSONObject and org.json.simple.JSONArray, and I hope net.sf.json.JSONArray also work same.

    You should put following string format for output (JSONArray array = new JSONArray(output); )

     {"YOUR_ARRAY_NAME": [{"username":"Hello","email":"hello@email.com","credits":"100","twitter_username":""},{"username":"Goodbye","email":"goodbye@email.com","credits":"0","twitter_username":""}]}
    

    Now this is String representation of JSONArray.

提交回复
热议问题