我一直在努力使用jackson Json Parser解析此feed。使用Jackson Json解析Google博客帖子
這裏是飼料:
{
"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();
}
}
Hi-thats great。一旦我添加了列表類型,然後如何使用Getters和setter像其他人一樣填充它們? –
那麼如果你把它公開,jackson會自動填充對象條目。事實上,在android中,使用公共成員來創建模型對象並不罕見(因爲getter和setter被認爲是更昂貴的 - 儘管谷歌的推薦很久以前就已經發布了......)。如果你希望它跟其他成員一樣,那麼就把它設爲私有,並添加一個getter和setter(分別爲getEntries,setEntries)--Jack仍然應該選擇這個屬性並根據JSON進行設置。 – Eggman87
@androidbloke有什麼好運? – Eggman87