I was able to convert a JSON string into a dictionary. With simple structure like I can get each element value by .Value, so np…
In the end I want/need a more complex structure like:
[code]Var jsonText As String = “{”“town”":{ ““City””:"“Boston”","“Team”":"“Red Sox”"} }
Var mydict As Dictionary
mydict = ParseJSON(jsonText)
[/code]
Target: I simply want to get value of f.e. element “Team” (-> “Red Sox”)
The problem: All my tries leads to an error message or jumps into the debug mode. Using Json in Javascript is a nobrainer as you use the dot-notation. I don’t understand why this is such a problem (even if possible) in Xojo. I couldn’t find any example showing JSON access.
These examples do not work:
[code]// Direct way
MessageBox ( mydict.Value(“City”) )
// Through hiearchy
MessageBox ( mydict.Value(“town”).Value(“City”) )
Dot notation like in Javascript does not xist in Xojo’s implementation of JSON
Not that it couldnt - it just doesnt
They could add runtime dot notation using operator_lookup
But that doesnt help at compile time
@Norman Palardy Agree, otherwise I would have found it in the documentation. I’m aware that Xojo demands strong data typing and therefore the “simple” dot-notation does not fit in that concept. Thanks for your explanation!
its because value return a variant and not a dictionary.
and because it not know the class it say .Value does not exists.
but you can cast/convert the return into a Dictionary