我有以下 JSON 响应。
{"message":"[{\"first_name\":\"Sushant\",\"last_name\":\"Bhatnagar\",\"receiver_id\":\"19\",\"docket_number\":\"Test12\",\"status\":\"open\"}]","code":200,"format":"json"}
我创建了两个类来解析它,如下所示:-
public class JsonResponse implements Serializable {
public String code;
public String format;
public List<Message> message;
}
公共类消息实现可序列化{
public String first_name;
public String last_name;
public String receiver_id;
public String docket_number;
public String status;
}
使用 GSOAP 解析 json ,出现上述错误。解析 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;
}