我正在使用as3corelib JSON庫並從URLLoader請求中解碼一些JSON。然而,我在與JSON.decode拋出一個錯誤的問題:AS3 JSON.decode拋出#1009錯誤
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()
我的代碼如下:
private function storeAssets(e:Event):void
{
// returned variables from PHP call
var variables:URLVariables = new URLVariables(e.target.data);
assets = JSON.decode(variables.assets);
}
我已經通過我的JSON輸入驗證器,它總是返回爲有效,以便我真的在撓撓我的腦袋。
爲什麼使用URLVariables? 如果您直接從服務器獲取json數據,則不應使用URLVariables,只需獲取響應字符串並將其直接傳遞給JSON.decode – Ben 2011-01-31 01:54:57