Home > Software design >  How to parse complex JSON using default methods in Flutter?
How to parse complex JSON using default methods in Flutter?

Time:10-05

I have a json String {"a":"{\"b\":7}"}. But it does not get decoded from the default library. I have written the following code:

import 'dart:convert';
void main() {
  String a =
        '{"a":"{\"b\":7}"}';
   print(json.decode(a));
}

Please help to parse the json.

CodePudding user response:

I implemented with your json string.

enter image description here

import 'dart:convert';
void main() {
  String a = '{"a":"{\"b\":7}"}';
  String b = a.replaceAll(RegExp(r'\\\""'), "\"");
  b = b.replaceAll(RegExp(r'\"{'), "\{");
  b = b.replaceAll(RegExp(r'\"}'), "\}");
  print(b);
  print(json.decode(b));
}

CodePudding user response:

To work with JSON objects that ave deep/multiple levels/recursive notation, then you can use a fantastic Dart package: enter image description here

  • Related