我有这样的json数组
{
"result": [
{
"nik": "1234",
"name": "test"
}
],
"status_code": 200
}
如何从该 json 数组/对象中获取所有数据?
这是我的颤振代码
final jsonData = json.decode(response.body);
Sample sample = Sample.fromJson(jsonData);
setState(() {
print(sample.result);
});
class Sample {
String result;
int code;
Sample({required this.result, required this.code});
@override
factory Sample.fromJson(Map<String, dynamic> json) {
return Sample(
result: json["result"],
code: json["code"]
);
}
}
但我收到了这个错误
Error: Expected a value of type 'String', but got one of type 'List<dynamic>'
at Object.throw_ [as throw] (http://localhost:53292/dart_sdk.js:5041:11)