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.
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: