flutter json转dart插件

https://javiercbk.github.io/json_to_dart/

json串

{
    "reason": "成功的返回",
    "result": {
        "stat": "1",
        "data": [{
            "uniquekey": "0bb54602fcc15111afca8452cc127d57",
            "title": "口香糖销量下降30%,你一定猜不到原因",
            "date": "2019-03-06 12:55",
            "category": "头条",
            "author_name": "解放网",
            "url": "http:\/\/mini.eastday.com\/mobile\/190306125558115.html",
            "thumbnail_pic_s": "http:\/\/01imgmini.eastday.com\/mobile\/20190306\/20190306125558_d2b6545a4b6273201218c32c6ffe436a_1_mwpm_03200403.jpg"
        }, {
            "uniquekey": "c92887585d01563c077c7be7f23dca87",
            "title": "《还珠格格》中的演员都老了,网友:五阿哥还是很帅",
            "date": "2019-03-06 12:44",
            "category": "头条",
            "author_name": "北青网",
            "url": "http:\/\/mini.eastday.com\/mobile\/190306124440102.html",
            "thumbnail_pic_s": "http:\/\/04imgmini.eastday.com\/mobile\/20190306\/20190306124440_bfad5f823d7fcad5e044754e095278ef_1_mwpm_03200403.jpg",
            "thumbnail_pic_s02": "http:\/\/04imgmini.eastday.com\/mobile\/20190306\/20190306124440_bfad5f823d7fcad5e044754e095278ef_4_mwpm_03200403.jpg",
            "thumbnail_pic_s03": "http:\/\/04imgmini.eastday.com\/mobile\/20190306\/20190306124440_bfad5f823d7fcad5e044754e095278ef_2_mwpm_03200403.jpg"
        }]
    },
    "error_code": 0
}

方式一

1..将json数据赋值到输入框中,点击创建Dart类,然后右边就是生成好的Dart代码,类名可以复制到编辑器后自行修改


image

2.创建一个Dart类,将类名自行修改一下


image

3.使用
 /*先将字符串转成json*/
    Map json = jsonDecode(jsonData);
    /*将Json转成实体类*/
    NewsBean newsBean=NewsBean.fromJson(news);
    /*取值*/
    String sats = newsBean.result.stat;

方式二

安装FlutterJsonBeanFactory插件生成

首先安装FlutterJsonBeanFactory这个插件,安装方式很简单,这里我就不说了。

安装完成后右键包目录,选择new


image

然后选择dart bean class File from JSON


image

然后将json数据粘贴至输入框,输入类名,点击make即可


image

你可能感兴趣的:(flutter json转dart插件)