1

I've got the following json response from spotify api:

{
   "artists" : {
     "href" : "https://api.spotify.com/v1/search?query=U2&type=artist&offset=0&limit=20",
   "items" : [ {
       "external_urls" : {
        "spotify" : "https://open.spotify.com/artist/51Blml2LZPmy7TTiAg47vQ"
     },
      "followers" : {
        "href" : null,
        "total" : 3146466
    },
     "genres" : [ "irish rock", "permanent wave", "rock" ],
      "href" : "https://api.spotify.com/v1/artists/51Blml2LZPmy7TTiAg47vQ",
      "id" : "51Blml2LZPmy7TTiAg47vQ",
     "images" : [ {
       "height" : 640,
         "url" : "https://i.scdn.co/image/e22d5c0c8139b8439440a69854ed66efae91112d",
       "width" : 640
      }, {
       "height" : 160,
       "url" : "https://i.scdn.co/image/7293d6752ae8a64e34adee5086858e408185b534",
        "width" : 160
      } ],
     "name" : "U2",
      "popularity" : 76,
      "type" : "artist",
     "uri" : "

I would like to get the id value, which in this case is

51Blml2LZPmy7TTiAg47vQ

but I can't figure out how to make a query in this json using dart.

I tried out as this answer but did not work.

Is there any way to make a query on json with flutter?

1 Answer 1

2

Try json.decode(string)['artists']['items'][0]['id']

json.decode decodes the string to a Map<dynamic, dynamic> containing nested Maps and Lists into which you can index. (Maps are indexed by key; Lists are indexed by integer.)

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

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.