私は次の JSON Response を持っています。
{"message":"[{\"first_name\":\"Sushant\",\"last_name\":\"Bhatnagar\",\"receiver_id\":\"19\",\"docket_number\":\"Test12\",\"status\":\"open\"}]","code":200,"format":"json"}
そして、以下のように解析するための2つのクラスを作成しました:-
public class JsonResponse implements Serializable {
public String code;
public String format;
public List<Message> message;
}
public class Message は Serializable を実装します{
public String first_name;
public String last_name;
public String receiver_id;
public String docket_number;
public String status;
}
json の解析に GSOAP を使用すると、上記のエラーが発生します。JSONを解析するためのコードは次のとおりです:-
public static JsonResponse readDockets(String mobileNumber) {
JsonResponse res = new JsonResponse();
HttpClient client = new DefaultHttpClient();
String service = "http://api.pod.iamwhiney.com:8994/api.php?path=/deliveryRecord/refresh/"+"9968395206";
HttpGet httpGet = new HttpGet(service);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity getResponseEntity = response.getEntity();
InputStream httpResponseStream = getResponseEntity.getContent();
Reader inputStreamReader = new InputStreamReader(httpResponseStream);
Gson gson = new Gson();
res = gson.fromJson(inputStreamReader, JsonResponse.class);
} else {
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return res;
}