title: How do I iterate JSON Map and retrieve key-value results in flutter Dart?
body: <p>I am working on json in flutter dart.</p>
  <pre><code>    final response = http.get('url'). 
  response.body returns this json String format: String stringJson = {&quot;symbols_returned&quot;:147,&quot;base&quot;:&quot;USD&quot;,&quot;data&quot;:{&quot;AED&quot;:&quot;3.672940&quot;,&quot;AFN&quot;:&quot;75.617000&quot;,&quot;ALL&quot;:&quot;109.780000&quot;,&quot;AMD&quot;:&quot;490.740000&quot;,&quot;ANG&quot;:&quot;1.797350&quot;,&quot;AOA&quot;:&quot;313.147500&quot;,&quot;ARS&quot;:&quot;37.864500&quot;,&quot;AUD&quot;:&quot;1.408450&quot;,&quot;AWG&quot;:&quot;1.800000&quot;,&quot;AZN&quot;:&quot;1.702500&quot;,&quot;BAM&quot;:&quot;1.727050&quot;,&quot;BBD&quot;:&quot;2.004250&quot;,&quot;BCH&quot;:&quot;0.008196&quot;,&quot;BDT&quot;:&quot;83.950500&quot;,&quot;BGN&quot;:&quot;1.726900&quot;,&quot;BHD&quot;:&quot;0.377470&quot;,&quot;BIF&quot;:&quot;1800.000000&quot;,&quot;BMD&quot;:&quot;1.000000&quot;,&quot;BND&quot;:&quot;1.357650&quot;,&quot;BOB&quot;:&quot;6.919100&quot;,&quot;BRL&quot;:&quot;3.729400&quot;,&quot;BSD&quot;:&quot;1.001300&quot;,&quot;BTC&quot;:&quot;0.000278&quot;,&quot;BWP&quot;:&quot;10.474000&quot;,&quot;BZD&quot;:&quot;2.018350&quot;,&quot;CAD&quot;:&quot;1.328050&quot;,&quot;CDF&quot;:&quot;1631.000000&quot;,&quot;CHF&quot;:&quot;1.000300&quot;,&quot;CLF&quot;:&quot;0.025048&quot;,&quot;CLP&quot;:&quot;658.100000&quot;,&quot;CNY&quot;:&quot;6.746600&quot;,&quot;COP&quot;:&quot;3121.850000&quot;,&quot;CRC&quot;:&quot;612.970000&quot;,&quot;CUP&quot;:&quot;1.001395&quot;,&quot;CVE&quot;:&quot;97.373000&quot;,&quot;CZK&quot;:&quot;22.793600&quot;,&quot;DJF&quot;:&quot;177.720000&quot;,&quot;DKK&quot;:&quot;6.589100&quot;,&quot;DOP&quot;:&quot;50.646500&quot;,&quot;DZD&quot;:&quot;118.840000&quot;,&quot;EGP&quot;:&quot;17.609500&quot;,&quot;ETB&quot;:&quot;28.413000&quot;,&quot;ETH&quot;:&quot;0.008377&quot;,&quot;EUR&quot;:&quot;0.883085&quot;,&quot;FJD&quot;:&quot;2.125900&quot;,&quot;GBP&quot;:&quot;0.773115&quot;,&quot;GEL&quot;:&quot;2.645000&quot;,&quot;GHS&quot;:&quot;5.276200&quot;,&quot;GIP&quot;:&quot;0.770005&quot;,&quot;GMD&quot;:&quot;49.550000&quot;,&quot;GNF&quot;:&quot;9127.200000&quot;,&quot;GTQ&quot;:&quot;7.765200&quot;,&quot;GYD&quot;:&quot;209.360000&quot;,&quot;HKD&quot;:&quot;7.846950&quot;,&quot;HNL&quot;:&quot;24.439500&quot;}
      }
  
  
      Map mapJson = json.decode(response.body) returns the following format: 
      {symbols_returned: 147, base: USD, data: {AED: 3.672940, AFN: 75.617000, ALL: 109.780000, AMD: 490.740000, ANG: 1.797350, AOA: 313.147500, ARS: 37.864500, AUD: 1.408450, AWG: 1.800000, AZN: 1.702500, BAM: 1.727050, BBD: 2.004250, BCH: 0.008196, BDT: 83.950500, BGN: 1.726900, BHD: 0.377470, BIF: 1800.000000, BMD: 1.000000, BND: 1.357650, BOB: 6.919100, BRL: 3.729400, BSD: 1.001300, BTC: 0.000278, BWP: 10.474000, BZD: 2.018350, CAD: 1.328050, CDF: 1631.000000, CHF: 1.000300, CLF: 0.025048, CLP: 658.100000, CNY: 6.746600, COP: 3121.850000, CRC: 612.970000, CUP: 1.001395, CVE: 97.373000, CZK: 22.793600, DJF: 177.720000, DKK: 6.589100, DOP: 50.646500, DZD: 118.840000, EGP: 17.609500, ETB: 28.413000, ETH: 0.008377, EUR: 0.883085, FJD: 2.125900, GBP: 0.773115, GEL: 2.645000, GHS: 5.276200, GIP: 0.770005, GMD: 49.550000, GNF: 9127.200000, GTQ: 7.765200, GYD: 209.360000, HKD: 7.846950, HNL: 24.439500, HRK: 6.537500, HTG: 82.810000, HUF: 281.363000, IDR: 14042.950000, ILS: 3.640660, INR: 71.165000, IQD: 1194.800000}}
  </code></pre>
  <p>The former is a String, while the latter is a Map object. My question are</p>
  <ol>
  <li>how do I iterate through and access each currency in Dart:
  e.g.   var currencyValue = stringJson['AED']</li>
  </ol>
  <p>The following is what I tried:   Both stringJson  and mapJson are returned from future method jsonTest().</p>
  <p>var stringJson = jsonOperation()</p>
  <pre><code> stringJson.then((onValue){
    if(onValue != null){
          onValue.forEach((k,v){  
         print(onValue['AED'])
          print('$k,$v');                                          
      });
    }
  });
  </code></pre>
  <p>The above code returns:
  print(onValue['AED']) printed null
  while print('$k,$v'); printed the following:</p>
  <pre><code>&gt; symbols_returned,147 
  &gt;I/flutter ( 4575): base,USD 
  &gt;I/flutter ( 4575):
  &gt; data,{AED: 3.673050, AFN: 74.450000, ALL: 110.130000, AMD: 489.850000,
  &gt; ANG: 1.795100, AOA: 313.147500, ARS: 38.223700, AUD: 1.415500, AWG:
  &gt; 1.794500, AZN: 1.705000, BAM: 1.728800, BBD: 2.001800, BCH: 0.008256, BDT: 83.907000, BGN: 1.735350, BHD: 0.377050, BIF: 1830.000000, BMD:
  &gt; 1.000000, BND: 1.350750, BOB: 6.913550, BRL: 3.764500, BSD: 1.000100, BTC: 0.000278, BWP: 10.505000, BZD: 2.010200, CAD: 1.330845, CDF:
  &gt; 1630.000000, CHF: 1.004050, CLF: 0.025048, CLP: 662.775000, CNY: 6.792400, COP: 3134.400000, CRC: 611.915000, CUP: 1.000550, CVE: 97.511500, CZK: 22.949000, DJF: 177.720000, DKK: 6.618750, DOP: 50.580000, DZD: 118.915000, EGP: 17.586000, ETB: 28.600000, ETH: 0.008363, EUR: 0.886920, FJD: 2.134350, GBP: 0.777245, GEL: 2.645000, GHS: 5.225000, GIP: 0.769990, GMD: 49.545000, GNF: 9220.000000, GTQ:
  &gt; 7.755600, GYD: 209.510000, HKD: 7.847850, HNL: 24.500000, HRK: 6.569900, HTG: 82.551000, HUF: 283.885000, IDR: 14100.500000, ILS: 3.645750, INR: 71.165000, IQD: 1190.000000, IRR: 42105.000000 } }
  </code></pre>
  <p>Instead of printing each currency in key value format. The problem is that I am not able to access each currency value.</p>