0
votes

I am attempting to parse some JSON from a URL via Flash/AS3. Here's my code so far:

import com.adobe.serialization.json.JSON;
import com.adobe.serialization.json.JSONDecoder;

var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest();
request.contentType = "application/json";
request.url="http://shaktiwarriors.guinness.trillitech.com/json/quiz/getNotAnsweredQuestions.php";
//request.url="demo.txt";
loader.load(request);

loader.addEventListener(Event.COMPLETE,loadConfirm);
loader.addEventListener(Event.COMPLETE,decodeJSON);

function loadConfirm(e:Event):void {
    trace("Load Successful" + "\n");
}

function decodeJSON(event:Event):void {
    var loader:URLLoader = URLLoader(event.target);
    trace(loader.data.toString() + "\n");
    var ids:Array= JSON.decode(loader.data);
    for (var i:int = 0; i < ids.length; ++i){
        trace(ids[i].id);
        my_txt.text = ids[i].id + "\n"
    }
}

The trace(loader.data.toString() + "\n") outputs a bunch of HTML. I'm sure I'm missing something simple.

Thanks for the help!

1
@taskinoor - when authenticated the JSON looks like this:[{"id":1},{"id":2},{"id":3},{"id":4},{"id":5},{"id":6},{"id":7},{"id":8},{"id":9},{"id":10},{"id":11},{"id":12},{"id":13},{"id":14},{"id":15},{"id":16},{"id":17},{"id":18}] - kevinstueber
Also, when I copy the JSON into a txt file and then run the code on that txt file it works fine. - kevinstueber

1 Answers

1
votes

When I tried the URL in browser it is saying that I need to login which is clearly a HTML, not a JSON. Before trying to parse JSON make sure that you loaded the correct thing. Looks like that you need to authenticate to load the JSON.