【发布时间】:2020-06-16 22:42:40
【问题描述】:
在 Flutter 中,无论我尝试解码什么 json 文件,我都会得到与上述标题相同的错误。 最初我认为这与我的项目有关,但在开始一个新的模板 Flutter 项目后,我仍然收到相同的错误。我的根文件夹中有 json 文件,并将它们添加到 pubspec.yaml 文件中:
assets:
- Sample-JSON-data.json
- Sample-employee-JSON-data.json
目前的Main.dart代码:
var jsonString = 'Sample-JSON-data.json';
var response = jsonDecode(jsonString);
print(response);
我已经在多个测试站点上验证了我的 json 数据,并在Flutter Documentation 中尝试了各种方法。 json数据:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.0763783444317,
-33.98045132346684
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.07774912725728,
-33.97470462237792
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.07774912725728,
-33.97470462237792
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.07774912725728,
-33.97470462237792
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.0763783444317,
-33.98045132346684
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.07774912725728,
-33.97470462237792
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.07774912725728,
-33.97470462237792
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.07774912725728,
-33.97470462237792
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
151.0763783444317,
-33.98045132346684
]
}
}
]
}
【问题讨论】: