gpt4 book ai didi

json - flutter :意外字符(在字符1处)

转载 作者:行者123 更新时间:2023-12-03 04:14:54 26 4
gpt4 key购买 nike

在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
]
}
}
]
}

最佳答案

实际上,您不是从json文件加载数据。

尝试:

var jsonString = await rootBundle.loadString('Sample-JSON-data.json')

关于json - flutter :意外字符(在字符1处),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60526069/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com