3

I wanted to get value from the API JSON object. My API JSON response is like this.

{
    "jobs": [
        {
            "id": 1,
            "user_id": "10",
            "job_id": "1",
            "experience": "12",
            "salary": "1122378"
            "job": { 
                "id": 1,
                "title": "PHP SENIOR DEVELOPER",
                "company_name": "Envato",
             
            }
        }
    ]
}

I wanted to get the title from the job JSON object. How can we get this value in flutter?

4 Answers 4

4
String jobTitle = json['jobs'][0]['job']['title'];
Sign up to request clarification or add additional context in comments.

Comments

1

if you get title of the job inside jobs section try below code :

var response = jsonDecode(response.body);
var title = response['jobs'][0]['job']['title'];

Comments

0

You can achieve this by doing the followng

final Map<String, dynamic> response = {
    "jobs": [
      {
        "id": 1,
        "user_id": "10",
        "job_id": "1",
        "experience": "12",
        "salary": "1122378",
        "job": {
          "id": 1,
          "title": "PHP SENIOR DEVELOPER",
          "company_name": "Envato",
        }
      }
    ],
  };
  final List<Map<String, dynamic>> jobs = response['jobs'];
  final Map<String, dynamic> job = jobs.first['job'];
  final String jobTitle = job['title'];
  print(jobTitle);

Comments

0

You can use https://app.quicktype.io/ to generate the deserialization, so you can handle it by models to prevent errors. Check: https://flutter.dev/docs/development/data-and-backend/json

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.