[英]decode complex and nested json in flutter / dart
Can anyone help me in decoding this complex json?谁能帮我解码这个复杂的 json?
{
"data": [
{
"order_id": 505597,
"order_status": "pending",
"order_status_name": "pending",
},
"billing": {
"first_name": "test name",
"last_name": "test",
"phone": "123456",
},
],
"success": true,
"statusCode": 200,
}
let's assume i have my own model class (i know how to write this) and an API class (which i decode json in here), but i need to access the values of decoded json from a third class and idk how to do that:/. let's assume i have my own model class (i know how to write this) and an API class (which i decode json in here), but i need to access the values of decoded json from a third class and idk how to do that: /.
This is too important to me, thanks in advance for ur answers.这对我来说太重要了,在此先感谢您的回答。
Here's a example:这是一个例子:
void main() {
var myJson = {
"data": [
{
"order_id": 505597,
"order_status": "pending",
"order_status_name": "pending",
"billing": [
{
"first_name": "test name",
"last_name": "test",
"phone": "123456",
},
],
},
{
"success": true,
"statusCode": 200,
}
]
};
print( (myJson["data"]![0]["billing"] as List)[0]["phone"] );
}
There are also libraries like this one: https://pub.dev/packages/dart_json_mapper还有像这样的库: https://pub.dev/packages/dart_json_mapper
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.