【发布时间】:2019-11-09 12:46:35
【问题描述】:
我有一个 URL,我正在尝试将 JSON 数据发布到该 URL,该 URL 将返回一个响应对象以及如何读取该 JSON 并将其显示在 TextView 中
尝试使用 VOLLEY 解析 JSON
{ “成功”:真, "returnCode":"成功", "returnMessage":"成功", “资源”:空, “错误”:空 }
VOLLEY JSON 解析技术对此有用吗?
【问题讨论】:
我有一个 URL,我正在尝试将 JSON 数据发布到该 URL,该 URL 将返回一个响应对象以及如何读取该 JSON 并将其显示在 TextView 中
尝试使用 VOLLEY 解析 JSON
{ “成功”:真, "returnCode":"成功", "returnMessage":"成功", “资源”:空, “错误”:空 }
VOLLEY JSON 解析技术对此有用吗?
【问题讨论】:
虽然我没有使用过 volley,但它可以在 Java 中工作。 首先,为了方便序列化,使用 DTO。
public class MyRespone extends Serializable {
private Boolean isSuccess;
private String returnCode;
private String returnMessage;
private String resource;
private String errors;
//getters and setters here
}
然后你可以使用 Gson/Jackson/FastJSON/Volley 来解析 RESPONSE OBJECT。
//Gson
Gson gson = new Gson();
MyResponse myResponse = gson.parseObject(RESPONSE_OBJECT_STR, MyResponse.class);
//jackson
ObjectMapper mapper = new ObjectMapper();
MyResponse myResponse = mapper.readValue(RESPONSE_OBJECT_STR,MyResponse.class);
你可以找到凌空版本来解决你的问题。 http://www.androiddeft.com/json-parsing-android-volley/
希望这会有所帮助。
【讨论】: