1

Can anyone help me in decoding this complex 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 :/ .

This is too important to me, thanks in advance for ur answers.

1
  • u mean getting the billing? Commented Feb 27, 2022 at 8:29

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.