Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解析JSON(AS3)_Json_Actionscript 3_Parsing - Fatal编程技术网

如何解析JSON(AS3)

如何解析JSON(AS3),json,actionscript-3,parsing,Json,Actionscript 3,Parsing,如何将下载的带有字符串的.json文件解析为字符串变量?使用as3corelib.swc 使用as3corelib(即不是本机JSON类)解析JSON的函数是'decode()' 如果输入json编码正确,则结果对象中应该有可用的字符串。如果字符串未正确转义,则解析字符串时可能会遇到问题,但这是输入数据的问题。下面是我当前项目的完整工作示例: protected function loadConfigFromUrl():void { var urlRequest:URLRequest

如何将下载的带有字符串的.json文件解析为字符串变量?使用as3corelib.swc

使用as3corelib(即不是本机JSON类)解析JSON的函数是'decode()'


如果输入json编码正确,则结果对象中应该有可用的字符串。如果字符串未正确转义,则解析字符串时可能会遇到问题,但这是输入数据的问题。

下面是我当前项目的完整工作示例:

protected function loadConfigFromUrl():void
{
    var urlRequest:URLRequest  = new URLRequest(CONFIG_URL);

    var urlLoader:URLLoader = new URLLoader();
    urlLoader.addEventListener(Event.COMPLETE, completeHandler);

    try{
        urlLoader.load(urlRequest);
    } catch (error:Error) {
        trace("Cannot load : " + error.message);
    }
}

private static function completeHandler(event:Event):void {
    var loader:URLLoader = URLLoader(event.target);
    trace("completeHandler: " + loader.data);

    var data:Object = JSON.parse(loader.data);
    trace("The answer is " + data.id+" ; "+data.first_var+" ; "+data.second_var);
    //All fields from JSON are accessible by theit property names here/
}

Adobe Animate中的actionscript 3.0

var obj:Object = [
    {
        "capital":"Santiago",
        "corregimientos":[
            {
                "santiago": "Capital of the province of Veraguas.",
                "habitantes":"It has an approximate population of 50,877 inhabitants (2014).",
                "area": "44.2 km²",
                "limits": "It limits to the north with the district of San Francisco, to the south with the district of Montijo, to the east with the district of Atalaya and to the west with the district of La Mesa."
            }
        ]
    }
];

trace("Capital " + obj[0].capital+" Corrections: "+obj[0].corregimientos[0].santiago);

使用JSON.parse()你能提供关于这个问题的更多信息吗?添加代码。你试过什么?你找了什么?这个网站不是关于其他人做的工作,并给你的代码。欢迎使用stack overflow,反正=)JSON现在内置到Flash Player中,不再需要名为-as3corelib的默认包。同样,Flash Player运行时处理JSON比as3corelib的实现要好。@Jason Sturges-同意,本机JSON解析器应该是首选。最初的问题是指as3corelib.swc,所以我指的是该代码。
var obj:Object = [
    {
        "capital":"Santiago",
        "corregimientos":[
            {
                "santiago": "Capital of the province of Veraguas.",
                "habitantes":"It has an approximate population of 50,877 inhabitants (2014).",
                "area": "44.2 km²",
                "limits": "It limits to the north with the district of San Francisco, to the south with the district of Montijo, to the east with the district of Atalaya and to the west with the district of La Mesa."
            }
        ]
    }
];

trace("Capital " + obj[0].capital+" Corrections: "+obj[0].corregimientos[0].santiago);