How do I get Construct 2 to Parse this JSON ? PLEASE HELP :(

Get help using Construct 2

Post » Tue Sep 29, 2015 10:13 am

This is the JSON:
{"Row":[{"id":"1","Item_Name":"Bushfly","Image_Path":"Monsters/Bushfly.png","Quantity":"1", "Description":"It's a Monster.","Seller":"Mr. Garrison","Star_Cost":"1","Category":"Monster"},{"id":"2","Item_Name":"Jebbie","Image_Path":"Monsters/Jebbie.png","Quantity":"1", "Description":"","Seller":"","Star_Cost":"1","Category":"Monster"}]}

I have this JSON on a String variable, now how do I get from this JSON Row[1].Item_Name ?

Thanks :)
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Tue Sep 29, 2015 1:14 pm

I don't have the rep to post links yet, but Google "construct 2 json" and hit the link "Example: Load data from Json to array and populate game"... I think that shows you what you need to know.
B
5
Posts: 17
Reputation: 259

Post » Tue Sep 29, 2015 2:12 pm

If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
85
Posts: 5,412
Reputation: 59,008

Post » Wed Sep 30, 2015 8:34 am

Thank you to the both of you :D

But it doesn't and wouldn't work for my JSON, my JSON contains an Array within an Array with Key Pairs :(
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Wed Sep 30, 2015 5:02 pm

Use the browser object to run some javascript to set a var to the json and access it that way or use yann's json plugin.

The first step for either is to convert the text into a valid c2 string of text. Partially covered here:
how-do-i-store-a-array-of-jsons-inside-an-array_p980660?#p980660

Let's use the browser object method. The first step it to convert that json text to both a valid C2 string of text and valid javascript.
1. paste your json text in notepad
2. replace ' with \'
3. replace " with '

That gives some valid text you can put in quotes and C2 will be happy with as input.

Next use the browser object's execute javascript action to set a variable to the json.
Code: Select all
"window.myjson = {'Row':[{'id':'1','Item_Name':'Bushfly','Image_Path':'Monsters/Bushfly.png','Quantity':'1', 'Description':'It\'s a Monster.','Seller':'Mr. Garrison','Star_Cost':'1','Category':'Monster'},{'id':'2','Item_Name':'Jebbie','Image_Path':'Monsters/Jebbie.png','Quantity':'1', 'Description':'','Seller':'','Star_Cost':'1','Category':'Monster'}]}"

That sets a global variable "myjson" to the json.

Next use the browser.execJs() expression every time you want to access a value.
browser.execJs("myjson.Row[1].Item_Name")
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Wed Sep 30, 2015 8:26 pm

R0J0hound, you are the light bringer !
B
12
S
3
Posts: 288
Reputation: 1,694


Return to How do I....?

Who is online

Users browsing this forum: Exabot [Bot] and 21 guests