Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
解码复杂的JSON?_Json_Jsonconvert - Fatal编程技术网

解码复杂的JSON?

解码复杂的JSON?,json,jsonconvert,Json,Jsonconvert,我想把这个复杂的JSON数据解码成普通的字符串,我如何用一种简单的方法来实现呢 更新 List<Map> list = []; @override void initState() { super.initState(); getList(); } void getList() async { //get data from internet/api //for

我想把这个复杂的JSON数据解码成普通的字符串,我如何用一种简单的方法来实现呢


更新

    List<Map> list = [];

      @override
      void initState() {
        super.initState();
        getList();
      }

      void getList() async {
        //get data from internet/api
        //for ex. I m using offline data
        var jsonData = [
  {
    "id": "1",
    "date": "18-Sep-2019",
    "paystub_Details": {
      "name": "Henry Nixon",
      "position": "Senior Programmer",
      "address": "30 Wertheim Crt",
      "suite": "Suite C16",
      "richmond": "Richmond Hill, ON L4B 1B9",
      "e_id": 21,
      "peroid": "10-Sep-2019 to 18-Sep-2019",
      "payment_date": "18-Sep-2019",
      "net_pay": 24600,
      "e_total": 38000,
      "d_total": 13400
    },
    "earn": {
      "detail": [
        {
          "description": "EI",
          "Units": 80,
          "Rate": 800,
          "Amount": 24000
        },
        {
          "description": "Hourly Wages",
          "Units": 80,
          "Rate": 800,
          "Amount": 14000
        }
      ]
    },
    "deduction": {
      "detail": [
        {
          "description": "CPP/QPP",
          "Units": 2400
        },
        {
          "description": "EI",
          "Units": 1400
        },
        {
          "description": "Fed Inc Tax",
          "Units": 2400
        },
        {
          "description": "Prov Inc Taxi",
          "Units": 2400
        },
        {
          "description": "Cpp/Qpp",
          "Units": 2400
        },
        {
          "description": "Cpp/Qpp",
          "Units": 2400
        }
      ]
    }
  },
  {
    "id": "2",
    "date": "18-Oct-2019",
    "paystub_Details": {
      "name": "Naveen Avidi",
      "position": "The Programmer",
      "address": "30 Wertheim Crt",
      "suite": "Suite C16",
      "richmond": "Richmond Hill, ON L4B 1B9",
      "e_id": 21,
      "peroid": "10-Oct-2019 to 18-Oct-2019",
      "payment_date": "18-Oct-2019",
      "net_pay": 24600,
      "e_total": 38000,
      "d_total": 13400
    },
    "earn": {
      "detail": [
        {
          "description": "EI",
          "Units": 80,
          "Rate": 800,
          "Amount": 25000
        },
        {
          "description": "Hourly Wages",
          "Units": 80,
          "Rate": 800,
          "Amount": 17000
        }
      ]
    },
    "deduction": {
      "detail": [
        {
          "description": "CPP/QPP",
          "Units": 2400
        },
        {
          "description": "EI",
          "Units": 1400
        },
        {
          "description": "Fed Inc Tax",
          "Units": 2400
        },
        {
          "description": "Prov Inc Taxi",
          "Units": 2400
        },
        {
          "description": "Cpp/Qpp",
          "Units": 2400
        },
        {
          "description": "Cpp/Qpp",
          "Units": 2400
        }
      ]
    }
  }
];

    setState(() {
      for(Map js in jsonData){
        list.add(js);
      }
    });
      }

      @override
      Widget build(BuildContext context) {
        return Container(
            padding: EdgeInsets.all(20),
            color: Colors.white,
            child: list.length < 1
                ? ListTile(
                    leading: CircularProgressIndicator(), title: Text('Loading...'))
                : ListView.builder(
                    itemCount: list.length,
                    itemBuilder: (rCon, rInd) {
                      return Card(
                          color: Colors.blueAccent,
                          child: Column(
                            mainAxisSize: MainAxisSize.min,
                            crossAxisAlignment:CrossAxisAlignment.start,            
                                        children: [
                            Padding(
                              padding: const EdgeInsets.all(5.0),
                              child: Text('${list[rInd]['paystub_Details']['name']}',
                                  style: TextStyle(
                                      color: Colors.white,
                                      fontWeight: FontWeight.bold,
                                      fontSize: 17)),
                            ),
                            Padding(
                              padding: const EdgeInsets.all(3.0),
                              child: Text(
                                  '${list[rInd]['paystub_Details']['position']}',
                                  style: TextStyle(
                                      color: Colors.white,
                                      fontWeight: FontWeight.bold,
                                      fontSize: 15)),
                            ),
                            SizedBox(height: 10),
                            Container(
                              padding: const EdgeInsets.all(7.0),
                              height: 50,
                              child: ListView.builder(
                                  scrollDirection: Axis.horizontal,
                                  itemCount: list[rInd]['earn']['detail'].length,
                                  itemBuilder: (con, ind) {
                                    return Container(
                                        padding: const EdgeInsets.all(5.0),
                                        margin: const EdgeInsets.all(5.0),
                                        decoration: BoxDecoration(
                                            borderRadius: BorderRadius.circular(7),
                                            color: Colors.cyanAccent),
                                        child: Text(
                                            '${list[rInd]['earn']['detail'][ind]['Amount']}',
                                            style: TextStyle(
                                                color: Colors.black,
                                                fontWeight: FontWeight.bold,
                                                fontSize: 15)));
                                  }),
                            )
                          ]));
                    }));
      }
List=[];
@凌驾
void initState(){
super.initState();
getList();
}
void getList()异步{
//从internet/api获取数据
//例如,我正在使用脱机数据
var jsonData=[
{
“id”:“1”,
“日期”:“2019年9月18日”,
“工资存根详细信息”:{
“姓名”:“亨利·尼克松”,
“职位”:“高级程序员”,
“地址”:“30 Wertheim Crt”,
“套件”:“套件C16”,
“里士满”:“里士满山,L4B 1B9上”,
“e_id”:21,
“peroid”:“2019年9月10日至2019年9月18日”,
“付款日期”:“2019年9月18日”,
“净薪酬”:24600,
“e_总数”:38000,
“d_总计”:13400
},
“赚取”:{
“细节”:[
{
“说明”:“EI”,
“单位”:80,
“费率”:800,
“数额”:24 000
},
{
“说明”:“小时工资”,
“单位”:80,
“费率”:800,
“金额”:14000
}
]
},
“扣除额”:{
“细节”:[
{
“说明”:“CPP/QPP”,
“单位”:2400
},
{
“说明”:“EI”,
“单位”:1400
},
{
“说明”:“美联储公司税”,
“单位”:2400
},
{
“说明”:“Prov公司出租车”,
“单位”:2400
},
{
“说明”:“Cpp/Qpp”,
“单位”:2400
},
{
“说明”:“Cpp/Qpp”,
“单位”:2400
}
]
}
},
{
“id”:“2”,
“日期”:“2019年10月18日”,
“工资存根详细信息”:{
“姓名”:“纳文·阿维迪”,
“职位”:“程序员”,
“地址”:“30 Wertheim Crt”,
“套件”:“套件C16”,
“里士满”:“里士满山,L4B 1B9上”,
“e_id”:21,
“peroid”:“2019年10月10日至2019年10月18日”,
“付款日期”:“2019年10月18日”,
“净薪酬”:24600,
“e_总数”:38000,
“d_总计”:13400
},
“赚取”:{
“细节”:[
{
“说明”:“EI”,
“单位”:80,
“费率”:800,
“金额”:25000
},
{
“说明”:“小时工资”,
“单位”:80,
“费率”:800,
“金额”:17000
}
]
},
“扣除额”:{
“细节”:[
{
“说明”:“CPP/QPP”,
“单位”:2400
},
{
“说明”:“EI”,
“单位”:1400
},
{
“说明”:“美联储公司税”,
“单位”:2400
},
{
“说明”:“Prov公司出租车”,
“单位”:2400
},
{
“说明”:“Cpp/Qpp”,
“单位”:2400
},
{
“说明”:“Cpp/Qpp”,
“单位”:2400
}
]
}
}
];
设置状态(){
for(jsonData中的映射js){
list.add(js);
}
});
}
@凌驾
小部件构建(构建上下文){
返回容器(
填充:边缘设置。全部(20),
颜色:颜色,白色,
子项:list.length<1
?列表磁砖(
前导:CircularProgressIndicator(),标题:Text('Loading…'))
:ListView.builder(
itemCount:list.length,
项目生成器:(rCon,外皮){
回程卡(
颜色:Colors.blueAccent,
子:列(
mainAxisSize:mainAxisSize.min,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
填充物(
填充:常数边集全部(5.0),
子项:文本(“${list[rInd]['paystub\u Details']['name']}”,
样式:TextStyle(
颜色:颜色,白色,
fontWeight:fontWeight.bold,
尺寸:17),,
),
填充物(
填充:常数边集全部(3.0),
子:文本(
“${list[rInd]['paystub_Details']['position']}”,
样式:TextStyle(
颜色:颜色,白色,
fontWeight:fontWeight.bold,
尺寸:15),,
),
尺寸箱(高度:10),
容器(
填充:常数边集全部(7.0),
身高:50,
子项:ListView.builder(
滚动方向:轴水平,
itemCount:list[rInd]['earn']['detail'].长度,
项目生成器:(con,ind){
返回容器(
填充:常数边集全部(5.0),
边距:所有常数边集(5.0),
装饰:盒子装饰(
边界半径:边界半径。圆形(7),
颜色:颜色。青色强调),
子:文本(
“${list[rInd]['earn']['detail'][ind]['Amount']}”,
样式:TextStyle(
颜色:颜色,黑色,
容重:Fo