Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.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
Android 例外情况:_InternalLinkedHashMap<;字符串,动态>';不是类型为';int';内铸_Android_Ios_Flutter - Fatal编程技术网

Android 例外情况:_InternalLinkedHashMap<;字符串,动态>';不是类型为';int';内铸

Android 例外情况:_InternalLinkedHashMap<;字符串,动态>';不是类型为';int';内铸,android,ios,flutter,Android,Ios,Flutter,在颤振应用程序中,我正在准备通过REST调用发送的数据。下面是我的代码 Future<void> saveOrderItemList(List<OrderItem> orderItems) async { int responsetag = 0; try { List jsonList = OrderItem.encondeToJson(orderItems); await http.post(_navLinks.saveOrd

在颤振应用程序中,我正在准备通过REST调用发送的数据。下面是我的代码

Future<void> saveOrderItemList(List<OrderItem> orderItems) async {
    int responsetag = 0;
    try {

      List jsonList = OrderItem.encondeToJson(orderItems);

      await http.post(_navLinks.saveOrderItems(),
          body: jsonList,
          headers: {
            "Accept": "application/json",
            "content-type": "application/json"
          }).then((http.Response response) {
        final int statusCode = response.statusCode;

        print("RESPONSE: " + response.body);
        print("STATUS CODE: " + statusCode.toString());

        if (statusCode < 200 || statusCode > 400 || response.body == null) {
          throw new Exception("Error while fetching data");
        } else {
          responsetag = int.parse(response.body);
        }
      });

      return responsetag;
    } catch (error) {
      throw (error);
    }
  }
下面的代码显示了为模型类生成的JSOB序列化

part 'order_item.g.dart';

/// An annotation for the code generator to know that this class needs the
/// JSON serialization logic to be generated.
@JsonSerializable()
class OrderItem {
  int idorderItem;
  FreshProducts freshProducts;
  Order order;
  ProductSize productSize;
  double orderItemExpectedPricePerKg;
  double orderItemQuantity;
  int dateCreated;
  int lastUpdated;

  OrderItem(
      {this.idorderItem,
      this.freshProducts,
      this.order,
      this.productSize,
      this.orderItemExpectedPricePerKg,
      this.orderItemQuantity,
      this.dateCreated,
      this.lastUpdated});

  /// A necessary factory constructor for creating a new instance
  /// from a map. Pass the map to the generated `_$OrderItemFromJson()` constructor.
  /// The constructor is named after the source class, in this case User.
  factory OrderItem.fromJson(Map<String, dynamic> json) =>
      _$OrderItemFromJson(json);

  /// `toJson` is the convention for a class to declare support for serialization
  /// to JSON. The implementation simply calls the private, generated
  /// helper method `_$OrderItemToJson`.
  Map<String, dynamic> toJson() => _$OrderItemToJson(this);

  static List encondeToJson(List<OrderItem> list) {
    List jsonList = List();
    list.map((item) => jsonList.add(item.toJson())).toList();
    return jsonList;
  }
}
// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'order_item.dart';

// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************

OrderItem _$OrderItemFromJson(Map<String, dynamic> json) {
  return OrderItem(
    idorderItem: json['idorderItem'] as int,
    freshProducts: json['freshProducts'] == null
        ? null
        : FreshProducts.fromJson(json['freshProducts'] as Map<String, dynamic>),
    order: json['order'] == null
        ? null
        : Order.fromJson(json['order'] as Map<String, dynamic>),
    productSize: json['productSize'] == null
        ? null
        : ProductSize.fromJson(json['productSize'] as Map<String, dynamic>),
    orderItemExpectedPricePerKg:
        (json['orderItemExpectedPricePerKg'] as num)?.toDouble(),
    orderItemQuantity: (json['orderItemQuantity'] as num)?.toDouble(),
    dateCreated: json['dateCreated'] as int,
    lastUpdated: json['lastUpdated'] as int,
  );
}

Map<String, dynamic> _$OrderItemToJson(OrderItem instance) => <String, dynamic>{
      'idorderItem': instance.idorderItem,
      'freshProducts': instance.freshProducts,
      'order': instance.order,
      'productSize': instance.productSize,
      'orderItemExpectedPricePerKg': instance.orderItemExpectedPricePerKg,
      'orderItemQuantity': instance.orderItemQuantity,
      'dateCreated': instance.dateCreated,
      'lastUpdated': instance.lastUpdated,
    };

为什么会发生这种情况?

responsetag=int.parse(response.body)@苏曼玛哈詹:我试着把它去掉。同样的结果。我想这是一个将列表转换为JSON的问题。
I/flutter (23028): type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'int' in type cast