Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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
String Actionscript将字符串反序列化为对象_String_Actionscript_Deserialization - Fatal编程技术网

String Actionscript将字符串反序列化为对象

String Actionscript将字符串反序列化为对象,string,actionscript,deserialization,String,Actionscript,Deserialization,是否有方法将字符串反序列化到actionscript中的对象: i、 e 应制作成适当的actionscript对象 这不是json,因为键没有用引号括起来。好的,对于这种类型的数据模式,我知道没有一种很好的方法可以做到这一点。假设您不能影响数据,使其更像JSON。。。下面是我脑海中的想法,我会在概念上尝试: var str:String = "{ id:1, value:['a', 500] }"; // strip off the { and } characters since we've

是否有方法将字符串反序列化到actionscript中的对象:

i、 e

应制作成适当的actionscript对象


这不是json,因为键没有用引号括起来。

好的,对于这种类型的数据模式,我知道没有一种很好的方法可以做到这一点。假设您不能影响数据,使其更像JSON。。。下面是我脑海中的想法,我会在概念上尝试:

var str:String = "{ id:1, value:['a', 500] }";
// strip off the { and } characters since we've nothing nice to do that for us...
var mynewString:String = str.slice(1, str.length - 1);
var stringItems:Array = mynewString.split(",");
var obj:Object = new Object();
for (var i in stringItems)
{
    var objProps:Array = stringItems[i].split(":");
    // kill off the quotes here
    obj[props[0]] = objProps[1].slice(1, objProps[1].length - 1);

    if ( obj[props[0]].indexOf('[') == 0 ) {
        // remove [ and ] if there
        var maybeStrArray:String = obj[props[0]].slice(1, str.length - 1);

        // right now assume we're an array based on our inbound data
        var strArr:Array = maybeStrArray.split(",");
        obj[props[0]] = strArr;
    }
}   
像这样或类似的东西。是的,它很粗糙,而且绝对可以用一种更灵活的方式制作(比如将字符串移动到数组转换为它自己的函数,这样我就可以在其他地方使用它)。这只是概念上第一个想到的答案


尝试一下,调整一下,看看是否有帮助。

好的,对于这种类型的数据模式,我知道没有一种很好的方法可以做到这一点。假设您不能影响数据,使其更像JSON。。。下面是我脑海中的想法,我会在概念上尝试:

var str:String = "{ id:1, value:['a', 500] }";
// strip off the { and } characters since we've nothing nice to do that for us...
var mynewString:String = str.slice(1, str.length - 1);
var stringItems:Array = mynewString.split(",");
var obj:Object = new Object();
for (var i in stringItems)
{
    var objProps:Array = stringItems[i].split(":");
    // kill off the quotes here
    obj[props[0]] = objProps[1].slice(1, objProps[1].length - 1);

    if ( obj[props[0]].indexOf('[') == 0 ) {
        // remove [ and ] if there
        var maybeStrArray:String = obj[props[0]].slice(1, str.length - 1);

        // right now assume we're an array based on our inbound data
        var strArr:Array = maybeStrArray.split(",");
        obj[props[0]] = strArr;
    }
}   
像这样或类似的东西。是的,它很粗糙,而且绝对可以用一种更灵活的方式制作(比如将字符串移动到数组转换为它自己的函数,这样我就可以在其他地方使用它)。这只是概念上第一个想到的答案


尝试一下,调整一下,看看是否有帮助。

您可以使用它进行JSON反序列化。真的不值得花时间编写自己的实现(除非您愿意)。

您可以使用JSON反序列化。真的不值得花时间编写自己的实现(除非您希望如此)。

字符串不能首先转换为json是否存在问题?这似乎是个好主意。实际上,转换应该是可能的。很抱歉,我之前没有考虑这个问题。是否存在一个rason字符串不能首先转换为json?这似乎是个好主意。实际上,转换应该是可能的。对不起,我没有早点考虑这个问题。我会接受这个答案,感谢你所做的努力。不过,我还是选择了将其正确格式化为json的解决方案,然后使用as3corelib。对于您所做的努力,我接受这个答案。不过,我使用了解决方案,将其正确格式化为json,然后使用as3corelib。