erdo
1
Hi,
I’m trying to parse this JSON data with the “Convert JSON to variable” action:
{
"response":
{
"success":"true",
"trophies":
[
{
"id":"9181",
"title":"Beta Tester 01",
"description":"Test the animation and controls demo.",
"difficulty":"Bronze",
"image_url":"http:\/\/i.gjcdn.net\/imgserver\/game-trophy\/75\/9181_1.jpg",
"achieved":"false"
},
{
"id":"9182",
"title":"Beta Tester 02",
"description":"Test the tutorial level demo.",
"difficulty":"Bronze",
"image_url":"http:\/\/i.gjcdn.net\/imgserver\/game-trophy\/75\/9182_1.jpg",
"achieved":"false"
},
]
}
}
How can I refer to “trophies” sub-elements loaded in the variable structure?
Thanks in advance for your help.
4ian
2
If you entered “Result” as the name of the variable where the converted JSON will be stored, you can then write in an expression:
Do =VariableString(Result.response.trophies.id) to the text of MyObject
so that the “MyObject” text object will display 9181.
More information about variables structures: wiki.compilgames.net/doku.php/en … evariables
And about how to parse JSON: wiki.compilgames.net/doku.php/en … s/jsonfile
erdo
3
Thanks Florian but I already try that and didn’t work.
Finally I get to this solution:
Do =VariableString(Result.response.trophies.0.id) to the text of MyObject
Where 0 is referencing to the first trophy item.
It seems that nameless items of a collection in a JSON string are referenced by a number (starting from 0).
1 Like
4ian
4
Sorry, I didn’t see that you were using an array.
Indeed, arrays element are named “0”, “1”, “2”…