我有这个 JSON 输出(使用 Chopper 库)
{"status":"success","error_message":[],"abc":[{"id":"124"},{"id":"125"}]}
如何获取对象 abc 中的 id ?
Response response = await _repo.submitData(title, description);
var abcResponse = ABCResponse.fromJson(response.body);
if (abcResponse.status == 'success') {
// I want print the latest id
}
}
ABC响应
part 'abc_response.g.dart';
@JsonSerializable()
class ABCResponse extends BaseResponse {
var abc = new List<ABC>();
ABCResponse();
factory ABCResponse.fromJson(Map<String, dynamic> json) =>
_$ABCResponse(json);
Map<String, dynamic> toJason() => _$WABCResponseToJson(this);
}
美国广播公司
@JsonSerializable()
class ABC {
ABC();
var id;
}
编辑
Response response = await _repository.submitData(title, description);
var abcResponse = ABCResponse.fromJson(response.body);
if (abcResponse.status == 'success') {
var user = json.decode(abcResponse.abc.toString());
print(user); // it printing null value
}