-1

I am getting a list of this type of json from a API. but I want to convert into a map with only its name, quoteCount, and slug.

{
"_id": "_gz-cfmqA1mr",
"name": "Alexander Pope",
"link": "https://en.wikipedia.org/wiki/Alexander_Pope",
"bio": "Alexander Pope (21 May 1688 – 30 May 1744) is regarded as one of the greatest English poets, and the foremost poet of the early eighteenth century. He is best known for his satirical and discursive poetry, including The Rape of the Lock, The Dunciad, and An Essay on Criticism, as well as for his translation of Homer.",
"description": "English poet",
"quoteCount": 3,
"slug": "alexander-pope",
"dateAdded": "2020-12-19",
"dateModified": "2020-12-19"
}

How to convert this json into Map?

2 Answers2

0

try this

import 'dart:convert'

Map<String,dynamic> map = jsonDecode(responseJson);
pmatatias
  • 3,491
  • 3
  • 10
  • 30
  • `Locations: No module for http://localhost:58509/dart_sdk.js Locations: No module for http://localhost:58509/dart_sdk.js Locations: No module for http://localhost:58509/dart_sdk.js Locations: No module for http://localhost:58509/dart_sdk.js 30 Locations: No module for http://localhost:58509/dart_sdk.js 3 Locations: No module for http://localhost:58509/` It is showing this error. – Abhijeet Saroha Oct 09 '22 at 03:42
  • 1
    And none of that has anything to do with the code of this answer. Are you starting a separate question? – Randal Schwartz Oct 09 '22 at 07:47
0

Try this

final response = await http.get(your url);
final Map<String, dynamic> data = json.decode(response.body);
Davis
  • 1,219
  • 2
  • 8
  • 17
  • Locations: No module for http://localhost:58509/dart_sdk.js Locations: No module for `http://localhost:58509/dart_sdk.js Locations: No module for http://localhost:58509/dart_sdk.js Locations: No module for http://localhost:58509/dart_sdk.js 30 Locations: No module for http://localhost:58509/dart_sdk.js 3 Locations: No module for http://localhost:58509/` It is showing a error that `no module for` – Abhijeet Saroha Oct 09 '22 at 03:41