class Product {
String status。
List<List> note;
List<List> table;
產品({this.status, this.note, this.table}) 。
Product.fromJson(Map<String, dynamic> json) {
status = json['status']。
if (json['note'] != null) {
note = <List> [];
json['note'].forEach((v) { note.add(new List.fromJson(v)); })。)
}
if (json['table'] != null) {
table = <List> [];
json['table'].forEach((v) { table.add(new List.fromJson(v)); })。)
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>()。
data['status'] = this.status。
if (this.note != null) {
data['note'] = this.note.map((v) => v.toJson() ).toList()。
}
if (this.table !=null) {
data['table'] = this.table.map((v) => v.toJson() ).toList()。
}
return data;
}
}
'List'類沒有一個名為'fromJson'的建構式。 請嘗試呼叫一個不同的建構式,或者定義一個名為'fromJson'的建構式。/ List.fromJson和v.toJson中的錯誤
。uj5u.com熱心網友回復:
錯誤資訊說得很直接。
你不能呼叫
new List.fromJson(v)
嘗試從你的json創建一個dart Iterable并使用.from()建構式
List<E>.from(
Iterable元素。
{bool growable = true} 。
)
或者嘗試其他由串列類定義的建構式 https://api.dart.dev/stable/2.14.2/dart-core/List-class.html
這個庫可能也有幫助 https://pub.dev/packages/json_serializable
uj5u.com熱心網友回復:
串列是一個抽象的類。它沒有一個建構式fromJson。如果你想從JSON轉換為串列,你必須給串列分配一個元素(Note),比如:
/Generic form
List<E>
//用于注釋
List<Note> 備注。
//像這樣呼叫
json['note'].forEach((v) { note.add(new Note.fromJson(v)); })。)
Note的模型類:
class Note {
String title。
String description;
Note({this.title, this.description})。)
Note.fromJson(Map<String, dynamic> json) {
title = json['title']。
description = json['description']。
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>()。
data['title'] = this.title。
data['description'] = this.description;
return data;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/307041.html
標籤:
