How do I Handle my Json response which contains boolean

Get help using Construct 2

Post » Mon Jul 18, 2016 7:19 am

My project has stucked on a point where i am using Json.
The JSON response from my PHP webservice is as follow :

{"result":true , "data":"1"}

but, the problem is i am unable to parse this Json into anything like dictionary or array because all of them take only TEXT or NUMBER. If i parse above JSON into dictionary then the value of result will contain 0 either it is true or false
so, is there any plugin or any other way to handle such booleans from JSON into C2?
B
6
S
2
Posts: 8
Reputation: 468

Post » Mon Jul 18, 2016 7:35 am

Use the browser object with the execjs expression. Say you have that json in a text variable called json.
You could get it with the expression:

Browser.execjs(json & ".result")

That should be enough I'd think. If not then then another idea is to convert the Boolean to a number.
Do that by changing ".result" to ".result?1:0"
B
89
S
30
G
95
Posts: 5,160
Reputation: 63,456

Post » Tue Jul 26, 2016 3:53 am

sorry for so late,
thanks R0J0hound.... Browser.execjs() worked for me :-)
B
6
S
2
Posts: 8
Reputation: 468

Post » Tue Jul 26, 2016 5:16 am

You can also use str() to fill a dictionary with int values...

For my map system, I use:
MapDictionary.Get(str(loopindex-1))

The values for the map tiles use numbers for some values, and strings for others. Using str() will populate numbers into the value field without any problem. :)

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
66
S
28
G
39
Posts: 2,967
Reputation: 28,819


Return to How do I....?

Who is online

Users browsing this forum: plinkie and 4 guests