Actionscript 3,解析JSON数据问题

时间:2011-09-28 03:15:23

标签: json parsing object actionscript

我正在向服务器发送请求,作为回报,我得到了一长串JSON。

{
  "response":"success",
  "assignments":{
    "17733":{
     "asnid":"17733",
     "asnname":"Yitzhak Rabin PPT",
     "asnclass":"11276",
     "asndue":"2011-10-03",
     "asnnotes":"5 Slides in Hebrew",
     "asnpriority":"0",
     "asnstatus":"open"
    },
    "9811":{
     "asnid":"9811",
     "asnname":"Java Chapter 1",
     "asnclass":"11270",
     "asndue":"2011-09-09",
     "asnnotes":"Review Exercises 1-14. Programming Exercises 1-6 ",
     "asnpriority":"0",
     "asnstatus":"done"
    },

    "9815":{
     "asnid":"9815",
     "asnname":"Hebrew Poems",
     "asnclass":"11276",
     "asndue":"2011-09-12",
     "asnnotes":"1 Name based poem, and One byline poem. See sheet for further reference.",
     "asnpriority":"0",
     "asnstatus":"done"
    },
    "11096":{
     "asnid":"11096",
     "asnname":"Java Ethics Essay",
     "asnclass":"11270",
     "asndue":"2011-09-15",
     "asnnotes":"",
     "asnpriority":"0",
     "asnstatus":"done"
    }
  }
}

为了解析这些数据,我使用的是com.adobe.serialization.json.JSON类。该类将数据转换为对象,但问题是我需要检查对象“17733”或“9811”中的什么并得到错误。 “1084:语法错误:在.17733之前期待右翼”

我的代码如下:

if (task == "getAssignments")
    {
        //trace(loader.data);
        var getAssnNumbers:Object = JSON.decode(loader.data);

//解码JSON数据

        for(var i:* in getAssnNumbers.assignments.17733)
        {
            assnNumbers.push(i);
            trace(i);
        }

//尝试跟踪存储在getAssnNumbers.assigments.17733中的数据         }

有办法做到这一点吗?我检查了属性是否被枚举并返回true,但我无法找到访问此数据的方法。

1 个答案:

答案 0 :(得分:2)

尝试使用括号表示法访问您的媒体资源:

getAssnNumbers.assignments["17733"]