我有一个Flash应用程序,在一个函数中,我必须解析一个JSON,像一个对象通过一些外部API传递,我不能改变。Actionscript3解析json与对象
的json是这样的:
{
"prodotti": [
{
"titolo": "test",
"marca": "",
"modello": "",
"cilindrata": "",
"potenza": "",
"alimentazione": "",
"images": {
"img": [
{
"thumb": "admin/uploads/img_usato/small/qekabw95L5WH1ALf6.jpg",
"big": "admin/uploads/img_usato/big/qekabw95L5WH1ALf6.jpg"
},
{
"thumb": "admin/uploads/img_usato/small/default.jpg",
"big": "admin/uploads/img_usato/big/default.jpg"
}
]
}
},
{
"titolo": "Motore Volvo TAMD 74 C",
"marca": "VOLVO PENTA",
"modello": "TAMD 74 C",
"cilindrata": "7.283 cm3",
"potenza": "331 kW a 2600 rpm",
"alimentazione": "Gasolio",
"images": {
"img": [
{
"thumb": "admin/uploads/img_usato/small/PmQwN4t4yp7P1YCWa.jpg",
"big": "admin/uploads/img_usato/big/PmQwN4t4yp7P1YCWa.jpg"
},
{
"thumb": "admin/uploads/img_usato/small/BWkjTGcy3pDM2LKRs.jpg",
"big": "admin/uploads/img_usato/big/BWkjTGcy3pDM2LKRs.jpg"
}
]
}
}
]
}
我想分析的对象中的图像。 的API给我一个对象不ASTRING或JSON和我有现在这样的功能:
function changeData (prodotto:Object) {
img_container.graphics.clear();
//here I want to enter and take thumb and big of images!!!
for (var index in prodotto.images.img) {
//trace('index: ' + index);
//trace("thumb: " + index.thumb + ' big: ' + index.big);
}
descrizione.htmlText = prodotto.testo_html;
titolo.text = prodotto.titolo;
alimentazione.text = prodotto.alimentazione;
potenza.text = prodotto.potenza;
cilindrata.text = prodotto.cilindrata;
modello.text = prodotto.modello;
marca.text = prodotto.marca;
}
功能工作正常,但不是for循环,我尽量把我的JSON的错误和拇指怎么可以在这个对象中检索这个信息?
谢谢
这是无效的JSON,请检查http://jsonlint.com/ – Ronnie
您有尾随逗号使其无效。如果这真的是你从API中得到的,而且你不能改变它,我建议向谁展示这个主题。这显然是无效的。 – Ronnie
我有更新我的JSON,我有错误的复制它,但问题是一样的,它不是@Ronnie –