0

If my response from my API looks like this.

{
    "message": "The given data was invalid.",
    "errors": {
        "email": [
            "The email has already been taken."
        ]
    }
}

How can I get the first key in the errors in dart? Currently I am doing

var body = json.decode(response.body);
print(body['errors']['email']);

But ['email'] could be dynamic, I just want whatever the first entry is of the errors

1 Answer 1

1

maybe you can try something like:

print(body['errors'].keys.toList()[0]);
Sign up to request clarification or add additional context in comments.

1 Comment

Beware... ".keys" could come out in any order. "First" doesn't really make sense here. Luckily your example has only one. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.