我一直在努力使用jackson Json Parser解析这个feed。
以下是Feed:
{
"responseData": {
"query": "Official Google Blogs",
"entries": [
{
"url": "http://googleblog.blogspot.com/feeds/posts/default",
"title": "<b>Official Blog</b>",
"contentSnippet": "5 days ago <b>...</b> <b>Official</b> weblog, with news of new products, events and glimpses of life inside <br> <b>Google</b>.",
"link": "http://googleblog.blogspot.com/"
},
{
"url": "http://googlewebmastercentral.blogspot.com/feeds/posts/default",
"title": "<b>Official Google</b> Webmaster Central <b>Blog</b>",
"contentSnippet": "Jul 12, 2013 <b>...</b> The <b>official</b> weblog on <b>Google</b> crawling and indexing, and on webmaster tools, <br> including the Sitemaps facility.",
"link": "http://googlewebmastercentral.blogspot.com/"
},
{
"url": "http://googlemac.blogspot.com/feeds/posts/default",
"title": "<b>Official Google</b> Mac <b>Blog</b>",
"contentSnippet": "Jun 22, 2012 <b>...</b> The <b>official</b> weblog about <b>Google</b> in the Apple Macintosh world.",
"link": "http://googlemac.blogspot.com/"
}
]
},
"responseDetails": null,
"responseStatus": 200
}
我设法获取除“条目”数组之外的所有对象反序列化。
任何想法?
以下是我的数据模型的代码:
public class UserModel {
public static final String TAG = UserModel.class.getSimpleName()
public static class ResponseData{
private String _query;
public String getQuery(){return _query;}
public void setQuery(String query){_query=query;}
// I am unable to get the entries parsing
}
private String responseStatus;
private String responseDetails;
private ResponseData responseData;
public ResponseData getresponseData() {
return responseData;
}
public void setresponseData(ResponseData responseData) {
this.responseData = responseData;
}
public String getresponseStatus() {
return responseStatus;
}
public void setresponseStatus(String responseStatus) {
this.responseStatus = responseStatus;
}
public String getresponseDetails() {
return responseDetails;
}
public void setresponseDetails(String responseDetails) {
this.responseDetails = responseDetails;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ResponseStatus [ResponseStatus=");
builder.append(responseStatus);
builder.append(responseData._query);
builder.append("]");
return builder.toString();
}
}
答案 0 :(得分:0)
我不知道我是否正确理解你的问题。
JSONObject data = new JSONObject(query);
JSONObject responseData = data.getJSONObject("responseData");
JSONArray entries = responseData.getJSONArray("entries");
List<JSONObject> pEntries = new ArrayList<JSONObject>();
for(int i = 0; i < entries.length(); i++){
pEntries.add(entries.getJSONObject(i));
}
从JSONObject中获取String调用getString(“name”);
答案 1 :(得分:0)
您需要将条目列表作为List类型添加到responseData类,还要创建一个表示Entry类的类(在下面的示例中称为条目,但可以随意调用它)。
public static class ResponseData{
public List<Entry> entries;
private String _query;
public String getQuery(){return _query;}
public void setQuery(String query){_query=query;}
// I am unable to get the entries parsing
}
编辑: 另外 - 确保您的Entry类包含JSON响应中的属性。它应该有url,title,contentSnippet和link属性。