How do I extract value from Json

前端 未结 8 1113
野的像风
野的像风 2020-11-30 05:23

I am getting a response String from server like below

{
  \"name\": \"Json\",
  \"detail\": {
    \"first_name\": \"Json\",
    \"last_name\": \"Scott\",
            


        
8条回答
  •  借酒劲吻你
    2020-11-30 05:39

    String jsonErrorString=((HttpClientErrorException)exception).getResponseBodyAsString();
    JSONObject jsonObj=null;
    String errorDetails=null;
    String status=null;
    try {
            jsonObj = new JSONObject(jsonErrorString);
            int index =jsonObj.getString("detail").indexOf(":");
                    errorDetails=jsonObj.getString("detail").substring(index);
                    status=jsonObj.getString("status");
    
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                item.put("status", status);
                item.put("errordetailMsg", errorDetails);
    

提交回复
热议问题