JSON.decode in extension

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Motimot
Posts: 3
Joined: 19 Dec 2016, 11:47

JSON.decode in extension

Postby Motimot » 23 Dec 2016, 18:37

Hello, my question is simple: How to use JSON.decode in AS extension?
I tried to import JSON, but it was unsuccessful, and I tried to google the solution but I haven't find anything.

So, I have a json text, how can i decode it to use it in the response?
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: JSON.decode in extension

Postby Lapo » 26 Dec 2016, 08:47

Hi,
I am not sure I fully understand. Can you please specify which SFS version you're using?
Also are you loading the JSON from a file?

Back to your question, JSON support is included in AS3 since Flash Player 11:
http://help.adobe.com/en_US/FlashPlatfo ... /JSON.html

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Motimot
Posts: 3
Joined: 19 Dec 2016, 11:47

Re: JSON.decode in extension

Postby Motimot » 28 Dec 2016, 06:57

I'm using sfs pro.
I want to load json file from url, in an extension that was written in AS.
How to do this?
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: JSON.decode in extension

Postby Lapo » 28 Dec 2016, 09:43

You could use the LoadVars class:
http://smartfoxserver.com/docs/1x/docPa ... /index.htm
(see under left menu, under "Other methods")

This emulates the LoadVars used in Flash and requires variables to be passed as a query string. In other words your webpage should return the JSON like this:

Code: Select all

json={ .... }&otherParam=123&nextParam=abc


If the web server returns pure JSON output then this won't work and you will have to integrate a java library to perform the HTTP call.
My suggestion is to use this:
http://hc.apache.org/httpclient-3.x/

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 13 guests