Home > Mobile >  Nested map json parsing in flutter
Nested map json parsing in flutter

Time:01-11

Json parsing in flutter in nested map in flutter

CodePudding user response:

import 'dart:convert';

void iterateJson(String jsonStr) {
  Map<String, dynamic> myMap = json.decode(jsonStr);
  String result = '';

  try{
    while(myMap.entries.isNotEmpty){    
      result  = '/'  myMap.entries.first.key;
      myMap = myMap.entries.first.value;
    }
  }catch(e){
//    print('reached end of data');
  }
  
  print(result.substring(1, result.length));


}
void main(){
  iterateJson('{"data":{"K1":{"K2":{"k3":true}}}}');
}
  •  Tags:  
  • Related