【发布时间】:2021-03-29 14:12:48
【问题描述】:
我有如下的json
{
"title": "DVG's Critique of the Congress High",
"body": [],
"field_body": {
"und": [
{
"value": "<p>The swift emergence of the High Command culture, which spawned the aforementioned dwarfs at many key-points revealed perhaps its most ugly face in the form of perpetually warring factions both in the Government and Party.
}
]
},
}
Json 有两个 body 字段。如果 body 为 null 或 0,我应该从 field_body 加载数据,但是当我在 getData 中声明它给我错误时,“String”类型不是“index”类型“int”的子类型。谁能帮我解决这个问题。
var data = await http.get(url);
var jsonData = json.decode(utf8.decode(data.bodyBytes));
return DetailData(
jsonData['title'],
jsonData['body']['und'][0]['value'] == 0
? jsonData['field_body']['und'][0]['value']
: jsonData['body']['und'][0]['value'],
jsonData['field_image_wp']['und'][0]['filename'],
jsonData['name']);
}
【问题讨论】:
标签: flutter