簡體   English   中英

在 flutter / dart 中解碼復雜和嵌套的 json

[英]decode complex and nested json in flutter / dart

誰能幫我解碼這個復雜的 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: /.

這對我來說太重要了,在此先感謝您的回答。

這是一個例子:

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"]  );
}

還有像這樣的庫: https://pub.dev/packages/dart_json_mapper

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM