从服务器获取JSON数据,但查询字段时显示错误 [英] JSON data fetched from server but showing error when querying fields

查看:67
本文介绍了从服务器获取JSON数据,但查询字段时显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够从flutter应用程序中的服务器成功获取JSON数据,但是在查询列表视图构建器的字段时却无法执行此操作,并且出现错误

I am able to successfully fetch the JSON data from the server in flutter application, but when querying for the fields for the list view builder I am not able to do so and I am getting the error

JSON数据

{
    "error": "false",
 

       "content": {
            "16": [
                [
                    {
                        "sod_pk": "31688",
                        "soh_fk": "23660",
                        "sqd_fk": "33294",
    
                        "order_header": {
                            "soh_pk": "23660",
                            "order_no": "16",
                        }
                    }
                ],
                [
                    {
                        "sod_pk": "31689",
                        "soh_fk": "23660",
                        "sqd_fk": "33293",
    
                        "order_header": {
                            "soh_pk": "23660",
                            "order_no": "16",
                        }
                    }
                ]
            ],
           
    
    
    
    
     "18": [
                [
                    {
                        "sod_pk": "31744",
                        "soh_fk": "23702",
                        "sqd_fk": "33354",
                        "order_header": {
                            "soh_pk": "23702",
                            "order_no": "18",
                        }
                    }
                ],
                [
                    {
                        "sod_pk": "31745",
                        "soh_fk": "23702",
                        "sqd_fk": "33356",
    
                        "order_header": {
                            "soh_pk": "23702",
                            "order_no": "18",
                        }
                    }
                ],
               
            ]
        }
    }

通话

 orderdetail = OrderModel.fromJson(json.decode(response.body));

我遇到的错误在这里

VERBOSE-2:ui_dart_state.cc(166)]未处理的异常:类型'(动态) => Null不是类型'(String,dynamic)=>的子类型. 'f'无效

VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: type '(dynamic) => Null' is not a subtype of type '(String, dynamic) => void' of 'f'

发生错误的功能

OrderModel.fromJson(Map<String, dynamic> json) {
        error = json['error'];
        if (json['content'] != null) {
          content = new List<OrderContent>();
    
         //here the error occurs
          json['content'].forEach((v) {
            content.add(new OrderContent.fromJson(v));
          });
        }
      }

订购内容分类

class OrderContent {
  String code;
  String name;

  String ordernumber;
  var order_header;

  OrderContent({this.code, this.name, this.ordernumber, this.order_header});

  OrderContent.fromJson(Map<String, dynamic> json) {
    code = json['code'];
    name = json['name'];
    ordernumber = json['order_no'];
    order_header = json["order_header"];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.code;
    data['name'] = this.name;
    data['order_header'] = this.order_header;
    data['order_no'] = this.ordernumber;
    return data;
  }
}

从JSON数据中,我无法从列表中获取任何字段,也无法从嵌套的order_header中获取

From the JSON data, I am not able to get any fields for my listing , neither from the nested order_header

如何从上面显示的JSON模型获取列表视图构建器的数据?

How should I get the data for my list view builder from the JSON model shown above?

推荐答案

您的json与您要使用的json不匹配.再次阅读您的代码,我相信您会明白的.

your json doesn't match with what you're trying to do with it. read your code once more I'm sure you'll get it..

这篇关于从服务器获取JSON数据,但查询字段时显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆