开发者

AS3 JSON.decode throwing #1009 error

I am using the as3corelib JSON library and decoding some JSON from a URLLoader request. However, I'm having issues with JSON.decode throwing an error:

TypeError: Error #1009: Cannot access a property or method of a null

object reference. at com.adobe.serialization.json::JSONTokenizer/nextChar() at com.adobe.serialization.json::JSONTokenizer() at com.adobe.serialization.json::JSONDecoder() at com.adobe.serialization.json::JSON$/decode() at Main/drawMap() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete()

My code is as follows:

 private function storeAssets(e:Event):void
 {
  // retur开发者_JAVA百科ned variables from PHP call
  var variables:URLVariables = new URLVariables(e.target.data);
  assets = JSON.decode(variables.assets);
 }

I have passed my JSON input into validators and it always returns as valid so I'm really scratching my head on this.


Your right in putting e.target.data into the URLVariables, as per this example: http://actionscriptexamples.com/2008/02/27/decoding-url-encoded-strings-in-a-flash-application-using-the-urlvariables-class-in-actionscript-30/

What I believe is happening is that URLVariables is decoding your entire string into an object, thus variables.assets is not in JSON format because it has already been converted. It could also be that variables.assets is not defined in the return data.

Trace out your variables.assets and see if it is null, or not in JSON format.

I would use eithervar variables:URLVariables = new URLVariables(e.target.data) or assets = JSON.decode(e.target.data) but not both at the same time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜