How to convert buffered-reader string to JSON in android?

两盒软妹~` 提交于 2019-12-08 03:34:54

问题


I get json response in Buffered Reader. Now How to convert buffered-reader string to JSON?

I get the String like

[
  {
    "email": "test@gmail.com",
    "password": "test@123!",
    "role": "monitor",
    "code": "0"
  }
]

回答1:


JSONArray aardata = new JSONArray(your buffered reader String):

And For Parse

  JSONObject obj = arrdata.getJsonObject(0);

      String email = obj.getString('email');



回答2:


You can create JSONArray with the response string by using:

JSONArray arrayJSON = new JSONArray(responseString);

And use getJSONObject() to get JSONObject and use getString() to get string value from particular JSONObject.



来源:https://stackoverflow.com/questions/21449853/how-to-convert-buffered-reader-string-to-json-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!