Flutter get key - Json

4,229

keys is an iterable, so you can convert it to a List an access each key by its index:

//Will print 'd'
print(json[0]["1"].keys.toList()[3]);

or iterate over each one:

//Will print all the keys (a b c d)
json[0]["1"].keys.forEach((key){ print(key); });
Share:
4,229
devT
Author by

devT

Updated on December 17, 2022

Comments

  • devT
    devT over 1 year

    How can I get the text of inside the key?

    I am able to use keys Using keys like this ..

    print(myData[0]["1"].keys);
    

    output: (a, b, c, d)

    JSON File looks like this:

     [
           {
               "1":{
                 "a": "text",
                 "b": "text",
                 "c": "text",
                 "d": "text"
               }
            }
       ]
    

    I was able to get first key name using.. keys.first But I also want to get other keys name but when I use keys.second or keys.third that doesn't work. how else I can get key's text/name? thanks