[英]Multiple JSON parsing
我需要有关解析的决定方面的帮助。 我需要进行JSON解析。 我这样做的方式是使用Volley进行一次通用样式的网络调用,并使用1个大型开关盒进行相关分析。 我将一个String添加到名为source的方法中,因此我知道需要进行哪些解析。
初始通话
private void getHomeScreen(){
networkCall(
url, //Url used to make the call
homeScreen); //The source of the parsing
}
网络调用完成后,将响应发送给解析器
onResponse{
parser(
jsonFile, //Response JSON file
source); //passing the String that had the source of the parser
}
将正确的响应发送到正确的解析器的解析器方法
private void parser(JSONObject, String source){
// the one massive switch case sending the HomeScreen to the relevant parser
}
有一个更好的方法吗? 必须有!
谢谢
如果我是你,我会看看Gson
for android。 Gson
是一个可以轻松解析JSON的库。 因此,无需创建自己的解析器。 使用Gson
您可以创建模型类,所有解析都将为您完成。
看一下本教程:
http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.