2016-08-02 9 views
0

lesen i die json vom Client zu bekommen und ich brauche, um Informationen aus dem json lesen dh MPRN = Str1234 POBoxNumber = Str1234 SubBuildingName = Str1234 enter image description here, wie die Informationen von json

iam unter Code

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 die unten stehende Störung zu erhalten:

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

Also, was ist Ihre Frage? Wird der Code kompiliert und ausgeführt oder nicht? Tut es etwas anderes als Sie erwarten? Wenn ja, was genau haben Sie erwartet und wie unterscheidet sich das von dem, was es wirklich tut? Erhalten Sie eine Fehlermeldung? Wenn ja, was ist die Fehlermeldung? – Jesper

+0

Welche Bibliothek? Welches Problem ist aufgetreten? – kai

+0

iam den folgenden Fehler erhalten: com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: Die Ausnahme in MappableContainerException konnte nicht zu einer Antwort zugeordnet werden, werfen erneut auf den HTTP-Container org.json.JSONException: JSONObject ["MPRN"] nicht gefunden. – String

Antwort

1

MPRN ist ein Kind zunächst RequestBody, müssen Sie RequestBody, bevor Sie können .getString ("MPRN")

0

diesen Code Versuchen

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, ich habe versucht, aber immer noch zeigt es Fehler: com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: Die Ausnahme in MappableContainerException konnte nicht zugeordnet werden, um eine Antwort zurückwerfen auf den HTTP-Container org.json .JSONException: JSONObject ["RequestBody"] nicht gefunden. – String

+0

thanku @himanshu Ich habe die Lösung, die ich gepostet habe – String

0

thnaku Jungs ... haben die Lösung

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");