0

I'm saving a string of this format "[{text: drding4disruption.com, quantity:10.0}, {text: google.com, quantity:6.0}]"

so reading some tutorials I got to know that we can use json.convert method to parse a string but here i'm getting

I did try to use json.decode(the_string); but It shows this error

FormatException: Unexpected character (at character 3)
E/flutter (14216): [{text: 4 medium size potatoes (boiled, peeled), quantity: 4.0, measure: <u...
E/flutter (14216):   ^
E/flutter (14216): 

how do I parse it so that I can access the map as well

2 Answers 2

1

Save the string in this format by adding double quote to fields and string values :

[
   {
      "text":"drding4disruption.com",
      "quantity":10
   },
   {
      "text":"google.com",
      "quantity":6
   }
]

Finally decode it: json.decode(the_string);

To consume it as YAML syntax take a look to this yaml package

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for answering but I can't do this because I'm the string from a api request or is there a way can I do it?
thats a third part API also I'm able to parse the data that API returns which also dosen't contains any double quotes for the keys and the child
In order to be able to parse data returned by your API request as JSON, the string must be in the above format!!
0

Use the import 'dart:convert' library and do it as following:
From JSON list to String

final String listAsString = jsonEncode(list);

From String to JSON list, simply reverse

final List list = jsonDecode(listAsString);

Make sure your JSON map keys and values are quoted like this

var list = [{"text": "drding4disruption.com", "quantity":10.0}, {"text": "google.com", "quantity":6.0}];

1 Comment

thanks for your answer, lemme save the string by encoding, maybe it can decode in that format as it was encoded

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.