1

How get 'ename' or 'job' from this json format eg.

{"items":[{"empno":7839,"ename":"KING","job":"PRESIDENT","mgr":null,....

For this json format use:

[
  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "[email protected]",

eg. title: Text(posts[index]['name'])

What to do with 'items'

2 Answers 2

1

Your solution is posts['items']['index']['ename'],

But I would recommend using the below approach,

Create a model class from your response, for example

class Welcome {
  String status;
  String error;
  int time;

  Welcome({this.status, this.error, this.time});

  factory Welcome.fromJson(Map<String, dynamic> json) {
    return Welcome(
    status: json['status'],
      error: json['error'],
    time: json['time'],
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['status'] = this.status;
    data['error'] = this.error;
    data['time'] = this.time;
    return data;
  }

}

Then convert json to model like this,

Welcome welcome = Welcome.fromJson(dataConvertedToJSON);

Now you can get data by calling its getters,

welcome.status

For converting json to model u can use this tool

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

Comments

1

You can access it with a key "items"

Text(posts['items'][index]['job'])

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.