Home > Software design >  How can we convert string into Map?
How can we convert string into Map?

Time:01-18

Problem : The method 'jasonDecode' isn't defined for the type '_LoadingState'.

I have already import the "import 'dart:convert';" but still jasonDecode is undefined. Is there any syntax change in it?

the code in which this error occurs is as follows

void getData() async {
  Response response =
      await get(Uri.parse('https://jsonplaceholder.typicode.com/todos/1'));
  Map<String, dynamic> data = jasonDecode(response.body);
  print(data);
}

void getData() async {
  Response response =
      await get(Uri.parse('https://jsonplaceholder.typicode.com/todos/1'));
  Map<String, dynamic> data = jasonDecode(response.body);
  print(data);
}

CodePudding user response:

It looks like you're trying to use the jsonDecode method from the dart:convert library, but you have a typo in your code. Instead of jasonDecode, it should be jsonDecode.

Here is the corrected code:

void getData () async { 
     Response response = await 
     get(Uri.parse('https://jsonplaceholder.typicode.com/todos/1')); 
     Map <String,dynamic>data = jsonDecode(response.body); 
     print(data);
 }

CodePudding user response:

There is a typo in your code. It should be "jsonDecode" instead of "jasonDecode"

The correct code is below:

void getData() async {
  Response response =
      await get(Uri.parse('https://jsonplaceholder.typicode.com/todos/1'));
  Map<String, dynamic> data = jsonDecode(response.body);
  print(data);
}

Hope it helps

  • Related