KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to be able to parse a string to an object that I can access using the dot notation e.g. myobject.property, instead of the array notation e.g. myobject['property']. The array notation works fine. Here's what I have so far. I have some XML: <level1 name="level1name"> <level2 type="level2Type"> <entry>level2entry</entry> <entry>level2entry</entry> </level2> </level1> Which converts to the JSON: { "level1": { "name": "level1name", "level2": { "type": "level2Type", "entry": [ "level2entry", "level2entry" ] } } } I have the following Dart code: Object jsonObject = JSON.parse("""{ "level1": { "name": "level1name", "level2": { "type": "level2Type", "entry": [ "level2entry", "level2entry" ] } } } """); print("my test 1 == ${jsonObject}"); print("my test 2 == ${jsonObject['level1']}"); print("my test 3 == ${jsonObject['level1']['name']}"); which produce the (desired) output: my test 1 == {level1: {name: level1name, level2: {type: level2Type, entry: [level2entry, level2entry]}}} my test 2 == {name: level1name, level2: {type: level2Type, entry: [level2entry, level2entry]}} my test 3 == level1name But when I try: print("my test 1 == ${jsonObject.level1}"); I get the following: Exception: NoSuchMethodException : method not found: 'get:level1' Receiver: {level1: {name: level1name, level2: {type: level2Type, entry: [level2entry, level2entry]}}} Arguments: [] Stack Trace: 0. Function: 'Object.noSuchMethod' url: 'bootstrap' line:717 col:3 Ideally, I want an object that I can access using the dot notation and without the compiler giving warning about Object n
Tags (comma-separated)
Save Edits
Cancel