How do I import data from a csv/json file?

Get help using Construct 2

Post » Fri Feb 08, 2013 12:07 am

Hi all,

Does anyone have a .capx file which shows how to import data from a file?

I've fiddled around with this for hours without success, including reading tutorials and forum posts and trying out plugins.

What I have managed is to hack together a "json" format in Excel and copy/paste this in using the "Load from json string" into an array.

I can create json and text files and bring them into the project. But loading from these files into an array just won't work for me.

So if anyone can help with a .capx showing where I'm going wrong, I'd appreciate it!

Thanks,

Mike
B
7
Posts: 38
Reputation: 476

Post » Sat Mar 02, 2013 9:06 pm

bump

Can nobody help with this?
B
7
Posts: 38
Reputation: 476

Post » Sat Mar 02, 2013 9:21 pm

Could I see your .capx ? Maybe it's just a little error from you ?
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Sat Mar 02, 2013 9:35 pm

condition System -> on start of layout
action AJAX -> request project file tag

You need to manually import the file into files folder. It should be a text file that is like....{"c2array":true,"size":[3,3,1],"data":[[["Shovel"],["Chisels"],["Pickaxe"]],[["2.75"],["0.75"],["2.25"]],[[3],[0],[4]]}.

Condition AJAX -> on completed tag
Action Array -> Load AJAX.lastData

That's how I did it in this capx:
https://dl.dropbox.com/u/27144902/inventory.capx

Although, I'm only able to get this to work by manualy loading file. I believe if you want to dynamically import or export JSON you'll need to experiment with AJAX request and post.
B
6
S
1
Posts: 24
Reputation: 549

Post » Tue Mar 05, 2013 4:23 am

@whiteclaws. Yep. An error by me for sure. I'm good at those. My capx only has the copy/paste version in though.

@Jase5z This is great! Thanks ;) I didn't have the "Load from json string ajax.lastdata" business working.

By the way, in this thread PePPo is having problems using Ajax with cocoon. So is it better to avoid using ajax? (I want to export to IOS) What do you think?

http://www.scirra.com/forum/topic62892.html
B
7
Posts: 38
Reputation: 476

Post » Tue Mar 05, 2013 4:35 pm

@Curious Mike "problems using Ajax with cocoon", I can't answer this. I just used the tool as explain in the manual.
B
6
S
1
Posts: 24
Reputation: 549

Post » Thu Dec 05, 2013 3:35 pm

doesn't make sense? so how do u load JSON variable/data in and access it by key/value?
B
5
Posts: 78
Reputation: 406


Return to How do I....?

Who is online

Users browsing this forum: Megavolt and 0 guests