1

Here is my code

Future ppp() async {
    var url ='my url here';
    final response = await http.get(Uri.parse(url));
    return response;
  }
   var data = await ppp();
   var id = json.decode(json.encode(data.body));
   print(id);

when i print, this is the result

[{"id":"168"}]

What i want to access is the 168

2 Answers 2

1
var parsedJson = json.decode(json.encode(data.body));
var id = parsedJson[0]['id']

Dunno why you encode and decode body

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

2 Comments

am getting this error: Exception has occurred. _TypeError (type 'String' is not a subtype of type 'int' of 'index'
var id = parsedJson[0]['id'].toString();
1

Try this,

var id = json.decode(json.encode(data.body));
print(id[0]["id"].toString());

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.