我正在解析一个Json,尽管一切正常,但仅在最后一个节点(即列表)上,它正在跳过将其添加到对象中的操作。我在解析json中提供的数据列表时出现错误。
这是Options对象的代码,其中数据存在于json-以下
class Options{
List<Data> data;
List<Value> value;
Options({this.data, this.value});
factory Options.fromJson(Map<String, dynamic> parsedJson){
var dataList = parsedJson['data'] as List;
List<Data> listData = dataList.map((i) => Data.fromJson(i)).toList();
var valueList = parsedJson['value'] as List;
List<Value> listValue = valueList.map((i) => Value.fromJson(i)).toList();
return Options(
data: listData,
value: listValue,
);
}
}
这是我的数据对象代码-
class Data{
String url;
List<String> captions;
Data({this.url, this.captions});
factory Data.fromJson(Map<String, dynamic> parsedJson){
var listCaptions = parsedJson['caption'] as List;
List<String> captionList = new List<String>.from(listCaptions);
return Data(
captions: captionList,
url: parsedJson['url'],
);
}
}
这是我的杰森-
{
"languages": [
{
"id": 1,
"name": "Test"
}
],
"questions": [
{
"id": 1,
"hint": [
"",
""
],
"name": [
"Qwerty",
""
],
"style": {},
"others": {},
"options": [
{
"data": [
{
"url": "https://qwerty.com/1.jpg",
"caption": [
"",
""
]
},
{
"url": "https://qwerty.com/2.jpg",
"caption": [
"",
""
]
}
],
"value": [
{
"title": [
"",
""
],
"answer": ""
}
]
}
],
"option_type": "note",
"validations": {
"required": false
}
}
]
}
使用换行符,我发现它正在跳过标题:captionList。它在captionList中包含数据,但不提供返回值。为什么无法识别并跳过?