android - 类似这样的JSON该怎么解析?(用Gson)
PHP中文网
PHP中文网 2017-04-17 17:59:22
0
1
292

如果我想用里面的stories数组,要怎么解析?
我定义好了一个News类和Story、TopStory两个内部类,然后写了下面的代码,不行。

Gson gson = new Gson();
storiesList = gson.fromJson(JSONData, new TypeToken<List<News.Story>>(){}.getType());

刚学,网上搜也没找到解决

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
洪涛
    public class Story {
        String title;
        String[] image;
        String ga_prefix;
        int type;
        int id;
    
        //setter & getter
    }
    
    public class Response {
        String date;
        List<Strory> stories, top_stories;
    
        //setter & getter
    }
    
    Goson goson = new Goson()
    Response res = goson.fromJson(jsonData, Response.class);

It’s done with just two classes, the above is the pseudo code

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!