gpt4 book ai didi

flutter - 接收方:空E/flutter(4835):尝试调用:[] (“Data”)

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

我正在尝试在flutter变量中获取JSON值,但它显示

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: Class 'int' has no instance method '[]'.
E/flutter ( 4835): Receiver: 1
E/flutter ( 4835): Tried calling: []("Data")
是什么原因导致我错了
future 功能代码:
 Future<void> saveData(dynamic jsonOfUser) async {
setState(() {
isUploading = true;
});
await Future.delayed(Duration(seconds: MyConstant.VAL_SECONDS), () {});
return post(
MyConstant.URL_USER_INSERT_LOGIN,
body: jsonOfUser,
).then((onRecievedResponse) {
var recievedValue = json.decode(onRecievedResponse.body);
status = recievedValue["status"];
userData = recievedValue[1]["Data"][5]["type"];

print(userData);
userInputValidation();

print(recievedValue);

setState(() {
isUploading = false;
});
return null;
});
}
我想从数据中获取类型的值
{
"status": 1,
"data": [
{
"id": "304",
"name": "Name1",
"username": "User Name1",
"password": "Pass1",
"type": "1"
}
]
这是Http调用的类:
class MyConstant {
static const String BASE_URL_ = 'http://95b5bc9c992c.ngrok.io/';

static const String URL_API = BASE_URL_ + 'fyp/';
static const String URL_Symptoms = 'http://531c3f6becb9.ngrok.io/?symptoms=';

static const String URL_USER_INSERT = URL_API + 'user_signup.php';
static const String URL_USER_INSERT_LOGIN = URL_API + 'user_login.php';
static const String URL_USER_Symptoms = URL_API + 'user_symptoms.php';
static const int VAL_SECONDS = 0;
}

最佳答案

试试这个recievedValue["data"][0]["type"]

关于flutter - 接收方:空E/flutter(4835):尝试调用:[] (“Data”),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63178140/

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