AS3 JSON解析JSON

2023-09-08 13:23:17 作者:I surrender 我投降

我都有点进退两难。我有一个JSON对象,它有一个格式,我不熟悉(始于一个数组 [] ,而不是一个对象 {} ),并想知道我怎么会分析它在AS3。对象是这样的:

I have a bit of a dilemma. I have a JSON object that has a format I'm unfamiliar with (starts with an array [] instead of an object {}) and was wondering how I might parse it in AS3. The object looks like:

[
    {
        "food": [
            {
                "name": "pasta",
                "price": 14.50,
                "quantity": 20
            },
            {
                "name": "soup",
                "price": 6.50,
                "quantity": 4
            }
        ]
    },
    {
        "food": [
            {
                "name": "salad",
                "price": 2.50,
                "quantity": 3
            },
            {
                "name": "pizza",
                "price": 4.50,
                "quantity": 2
            }
        ]
    }
]

我真的不知道我是怎么得到每种食物阵列,并在其中的每个对象。任何帮助将大大AP preciated!谢谢!

I don't really know how I get to each food array, and each object within it. Any help would be greatly appreciated! Thanks!

推荐答案

从flash播放器11,和SDK 4.6有对JSON的原生支持。要使用它,你应该修改

from flash player 11, and sdk 4.6 there is native support for json. To use it you should change

var foods:Array = JSON.decode(jsonstring);

var foods:Array = JSON.parse(jsonstring);

而JSON是不是从的as3corelib而是从SDK本身。 pretty的要快得多;)

while JSON is not from as3corelib but from sdk itself. Pretty much faster ;)