Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter get key - Json

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

like image 420
devT Avatar asked Oct 23 '25 11:10

devT


1 Answers

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); });
like image 96
Carlos Javier Córdova Reyes Avatar answered Oct 26 '25 01:10

Carlos Javier Córdova Reyes