Home > OS >  How to convert a multi-member Json on Dart?
How to convert a multi-member Json on Dart?

Time:06-16

I'm getting a String(json) from a http.post, but the Json has multiple members separated by comma. Like:

{"name":"John",
 "age":30,
 "car":null
},{
 "name":"Lisa",
 "age":20,
 "car":null
},{ etc...

I do:

var string = response.body;
var json = jsonDecode(String);

That works fine when I have just 1 member. But when I get more than one (like in the example), I get the following error:


ERROR: FormatException: Unexpected character

"car":null"},{"name":"Lisa",
            ^

Any suggestions? Thanks <3

CodePudding user response:

I think you should form the string like an array to make it parsable:

var string = response.body;
var json = jsonDecode('[$string]');
  • Related