2016-08-02 76 views
0

的信息我会得到来自客户端的JSON,我需要获得使用下面的代码读取来自JSON即MPRN = Str1234 POBoxNumber = Str1234 SubBuildingName = Str1234 enter image description here如何读取JSON

IAM信息

JSONObject inputs = new JSONObject(Json); 
jsonobject = (JSONObject) 
inputs.get("Request"); 
String mprn = jsonobject.getString("MPRN");   
String Pno = jsonobject.getString("POBoxNumber");  
String subB = jsonobject.getString("SubBuildingName"); 

IAM提示以下错误:

com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container org.json.JSONException: JSONObject["MPRN"] not found. 
+0

那么,什么是你的题?代码是否编译并运行?它会做别的事吗?如果是这样,那么你究竟期待什么,这与它的真正作用有什么不同?你有错误信息吗?如果是,那么错误信息是什么? – Jesper

+0

哪个库?发生了什么问题? – kai

+0

iam获取以下错误:com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE:包含在MappableContainerException中的异常无法映射到响应,重新投掷到HTTP容器 org.json.JSONException:JSONObject找不到[“MPRN”]。 – String

回答

1

MPRN是一个孩子RequestBody的,你需要RequestBody之前,首先你可以.getString( “MPRN”)

0

试试这个代码

JSONObject inputs = new JSONObject("Json"); 

    JSONObject requestBody = inputs.getJSONObject("RequestBody"); 
    JSONObject address = requestBody.getJSONObject("Address"); 

    String mprn = requestBody.getString("MPRN"); 
    String Pno = address.getString("POBoxNumber"); 
    String subB = address.getString("SubBuildingName"); 
+0

thanku,我试过但仍显示错误:com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE:包含在MappableContainerException中的异常无法映射到响应,重新投掷到HTTP容器 org.json .JSONException:未找到JSONObject [“RequestBody”]。 – String

+0

thanku @himanshu我得到了我发布的解决方案 – String

0

thnaku家伙...得到了解决

JSONObject inputs = new JSONObject(json); 
jsonobject = (JSONObject) inputs.get("Request"); 
JSONObject requestBody = jsonobject.getJSONObject("RequestBody"); 
    JSONObject address = requestBody.getJSONObject("Address"); 

    String mprn = requestBody.getString("MPRN"); 
    String Pno = address.getString("POBoxNumber"); 
    String subB = address.getString("SubBuildingName");