1

我一直在努力使用 jackson Json Parser 解析这个提要。

这是饲料:

    {
"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();
    }

}
4

2 回答 2

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");

于 2013-07-21T22:58:16.590 回答
0

您需要将条目列表作为 List 类型添加到您的 responseData 类,并创建一个表示 Entry 类的类(在下面的示例中称为 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 属性。

于 2013-07-21T23:21:09.537 回答