0

I have a string that looks like this when printed out:

[['20/11/2019', 'PERSONAL INFO', 'SCRITTO', 5.5, 'SI', ''], ['11/10/2019', 'PERSONAL INFO', 'SCRITTO', 9.5, 'SI', ''], ['02/10/2019', 'PERSONAL INFO', 'ORALE', 8.0, 'SI', '']]

It's already structured as a list of lists but when I run print(ing is String) I get true (ing is the name of the string). I already saw and tried to use the answer provided here Dart: Convert String representation of List of Lists to List of List but the smaller lists always end up without a separator. Any advice?

geomikeo
  • 19
  • 4
  • The string looks like valid JSON, so you could treat it as such. That being said, the linked answer also suggests this, but judging from your reaction that doesn't appear to be what you are going for. Could you post an example of what you would want the resulting list to look like? – Abion47 Jan 13 '20 at 21:39

1 Answers1

0

I'm going to assume this is a JSON list stored as a String and you want to get the actual object representation. If that's the case, you'll want to take a look at dart:convert's json.decode, which takes a String and returns a Dart primitive (e.g., List<dynamic>, Map<String, dynamic>, String, int, etc.) depending on the JSON contents.

Ben Konyi
  • 2,849
  • 12
  • 20
  • 1
    Strictly speaking, `json.decode` returns `dynamic`, which could be a primitive value, a list, or a map. – Abion47 Jan 13 '20 at 21:40
  • do you mean the jsonDecode function or is that a different one? – geomikeo Jan 14 '20 at 09:09
  • The `jsonDecode` function is just a shortcut for calling `json.decode`. It's only there because there was existing code using `json` as a local variable which shadowed the `json` constant from `dart:convert`, and they can use `jsonDecode(json)` instead. – lrn Jan 14 '20 at 09:41
  • I just tried passing ing (the string) into jsonDecode and it throws this error: Unhandled Exception: FormatException: Unexpected character (at character 3) – geomikeo Jan 14 '20 at 13:50
  • Just found the issue: I was passing each value of the dictionary as a string instead of a list. Thank you very much for your time! – geomikeo Jan 14 '20 at 14:46