Tom
Tom

Reputation: 5994

AS3 - Decode JSON

I'm new to JSON. This is the .json I want to decode but I always get this error:

JSONParseError: Unexpected h encountered

This is my code:

import com.adobe.serialization.json.JSON;
    //
    var loader:URLLoader = new URLLoader();
    var request:URLRequest = new URLRequest();
    request.url = "twitter.json";
    //
    loader.load(request);
    loader.addEventListener(Event.COMPLETE, decodeJSON);
    //
    function decodeJSON(event:Event):void {
        var loader:URLLoader = URLLoader(event.target) 
    var jsonArray:Array = JSON.decode(loader.data);
    }

What's wrong with it? Thanks.

Upvotes: 1

Views: 5097

Answers (2)

Robert
Robert

Reputation: 21

It's an array not an object, so do this:

//var jsonArray:Array = JSON.decode(loader.data);
var jsonObject:Object = JSON.decode(loader.data);

Upvotes: 2

daleyjem
daleyjem

Reputation: 2674

you need to escape your href double quotes with a backspace

Upvotes: 0

Related Questions