when I want to get a value from a json form in flutter, i face this error it says
type 'String' is not a subtype of type 'int' of 'index'
and Im using http: ^0.13.4
and this is my code
void getData() async{
Response res=await get("https://something.com");
String dat=res.body;
var datta=jsonDecode(dat)['title'];
print(datta);
}
how can I fix this problem?
You should handle the request in this way, worked for me:
Then you convert the string into a JSON object using dart:convert library:
That should be enough, but I suggest you to implement a model class to handle your response, and another model to handle the kind of object you are working with (e.g. Book, Post, Product, etc).