I have json array like this
{
"result": [
{
"nik": "1234",
"name": "test"
}
],
"status_code": 200
}
How I can get all data from that json array/object?
and this my flutter code
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"]
);
}
}
but I got this error
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)