Hi there, i have a little problem with a JSON
{"error":{"code":100},"success":false}
How can i get the code? I tried it with .lookup and .value…but im a noob with this JSON thing.
Hi there, i have a little problem with a JSON
{"error":{"code":100},"success":false}
How can i get the code? I tried it with .lookup and .value…but im a noob with this JSON thing.
So let’s say that string is in a variable j
:
dim root as new JSONItem( j )
dim errorItem as JSONItem = root.Value( "error" )
dim code as integer = errorItem.Value( "code" )
Thank you that works perfect.
Only for understanding, why is success here as variant? For Example i can get all like this:
dim root as new JSONItem(addresult)
dim errorItem as JSONItem = root.Value("error")
dim succ as variant = root.Value("success")
dim code as string = errorItem.Value("code")
You could also use Boolean for success.
yes but for example string dont work?
JSONItem.Value returns a Variant because that’s the type best suited for the kinds of values a JSON object can hold. These are:
The JSON object itself can either act as an Array of these elements, or a Dictionary where string keys are used to retrieve the elements.
In this case, the JSON acts as a Dictionary with two keys, “error” and “success”. The value for “error” is another JSON object that also acts as a Dictionary (key = “code”). The value for “success” is a Boolean.
You can retrieve the value either as a Variant (which can hold anything) or as it’s native value.
Important: Unlike a Xojo Dictionary, keys in a JSON dictionary object are case-sensitive, so a key “code” can exist alongside the keys “Code”, “CODE”, and “codE”.
I hope this answers your question.
Thank you maybe next time i get it on my own