Skip to main content
This topic has been closed for replies.

3 replies

Participant
March 6, 2013

How to make stringify() returns unicode escape sequences(like \uxxx) rather than native unicode characters?

January 27, 2013

Here is very simple example of importing a json file named "fruits.js".  This example has the text for the imported file followed by the actionscript package coding...

// Content for js file named "fruits.js"…

{

"fruits":

[

{

"fruit":"Apple",

"fruitcolor":"Red"

},

{

"fruit":"Banana",

"fruitcolor":"Yellow"

},

{

"fruit":"Grapes",

"fruitcolor":"Purple"

}

]

}

// AS3 code to import and parse the file…

package {

    import flash.display.Sprite;

    import flash.events.*;

    import flash.net.*;

    public class AddJson extends Sprite {

        public var loader:URLLoader = new URLLoader();

        public function AddJson() {

//loader set-up

var request:URLRequest = new URLRequest("fruits.js");

loader.load(request);

loader.addEventListener(Event.COMPLETE, jsonLoaded);

        }

public function jsonLoaded(event:Event):void {

            var jsonContent:URLLoader = URLLoader(event.target);

//json

var data:Object = JSON.parse(jsonContent.data);

trace(data.fruits.length);

trace("The first one is " + data.fruits[0].fruit + " : " + data.fruits[0].fruitcolor);

var secondFruit:String = data.fruits[1].fruit;

trace("secondFruit as string data: " + secondFruit)

        }

    }

}

Participant
August 23, 2012

what is wrong with this page? It does not show in the Top Level package. Where are methods? Errors?

jrunrandy
Adobe Employee
Adobe Employee
August 23, 2012

If you don't see anything on a page, it's usually because of filter settings.

In Packages and class filters, towards the top of the page, for Runtimes, be sure you have selected AIR 3.4 and earlier and Flash Player 11.4 and earlier

HTH

Randy Nielsen

SeniorContent and Community Manager

Adobe

Participant
August 23, 2012

It's little bit (a lot) confusing but yes, that was the problem. You should think of improving the usability.

Another question: parse method does not throw an error is the text string is not valid JSON representation?