flutter报错解决 Error: FormatException: SyntaxError: Unexpected token m in JSON at position 1
程序员文章站
2022-07-12 11:30:41
...
Error: FormatException: SyntaxError: Unexpected token m in JSON at position 1
首先说明一下后端正确的需要返回的json格式如下:
{
"mydata":"[{
"title": "如何使用Arthas进行JVM取证系统安全",
"url": "sssssssssss",
"time": "ssss",
"score": "90",
},
{
"title": "如何使用Arthas进行JVM取证系统安全",
"url": "yyyyyyyyyyy",
"time": "443333",
"score": "90",
}]"
}
这种错误就是json格式的错误,我在代码中对返回的响应数据如下处理:
Future<String> getHttp() async {
try {
Response response = await Dio().get(BASEURL);
return response.data.toString();
} catch (e) {
print("我的dio错误--${e}");
}
return null;
}
response.data.toString(),这里toString操作使得后端返回的json数据变为了以下格式:
{mydata: [{
"title": "如何使用Arthas进行JVM取证系统安全",
"url": "sssssssssss",
"time": "ssss",
"score": "90",
},
{
"title": "如何使用Arthas进行JVM取证系统安全",
"url": "yyyyyyyyyyy",
"time": "443333",
"score": "90",
}]}
可以看出跟正确的json相比,该json的mydata字段少了双引号,因此无法被识别。
正确的处理方法应该是:
Future<String> getHttp() async {
try {
Response<String> response = await Dio().get(BASEURL);
return response.data;
} catch (e) {
print("我的dio错误--${e}");
}
return null;
}
上一篇: 报错: Error in created hook: “SyntaxError: Unexpected token u in JSON at position 0
下一篇: 算法之线性查找法
推荐阅读
-
vue 报错Error in mounted hook: "SyntaxError: Unexpected token u in JSON at position 0"
-
报错: Error in created hook: “SyntaxError: Unexpected token u in JSON at position 0
-
flutter报错解决 Error: FormatException: SyntaxError: Unexpected token m in JSON at position 1
-
JSOIN.parse()报错:Uncaught SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse (
) -
JSON字符格式报错:VM40:1 Uncaught SyntaxError: Unexpected token E in JSON at position 0
-
SyntaxError: Unexpected token R in JSON at position 0 报错的解决方法
-
报错 SyntaxError: Unexpected token R in JSON at position 0 at JSON.parse (<anonymous>)的解决方法
-
解决报错:Uncaught SyntaxError: Unexpected token “xxx” in JSON at position 0
-
解决报错信息之:SyntaxError: Unexpected token R in JSON at position 0
-
JS报错解决:SyntaxError: Unexpected token 《 in JSON at position 0