gpt4 book ai didi

string - 我可以在不更改项目顺序的情况下将 JSON 字符串转换为 Flex ArrayCollection 吗?

转载 作者:行者123 更新时间:2023-12-02 02:00:44 25 4
gpt4 key购买 nike

关于这个问题,我已经从 Java 生成动态字符串。每次字符串格式更改时,例如字符串格式是

[{"BranchName":"Corporate Office","Date":"08\/03\/2013","SPName":"Pharmacy","SPAmount_5-00%":"100.00","SPVATAmount_5-00%":"15.00","SPOtherCharges_5-00%":"30.00","SPAmount_14-50%":"200.00","SPVATAmount_14-50%":"39.00","SPOtherCharges_14-50%":"71.00","SPColTPA":"100.00","SPColChequeDD":"50.00","SPHdfcCC":"100.00","SPIdbiCC":"100.00","SPColCash":"50.00","Difference":"55.00"},

但是当我用下面的代码转换数组集合时。

var rawData:String = String(event.result); 
var arr:Array = (JSON.decode(rawData) as Array);
var dp:ArrayCollection = new ArrayCollection(arr);

但数组集合顺序更改为默认排序,如 [Branch, Date, Difference,.. ] 。但我想要与字符串格式顺序相同。那么如何防止默认订单。

最佳答案

实际上,您在这里描述的是一组对象(您的示例只包含一个对象)。在JSON解析到数组中,每个对象确实是按照声明的顺序排列的;但是在创建的对象中,属性可能不会以相同的顺序列出。

例如:

'[ {"Branch":"Corporate", "Department":"Finance", "Cost":"10000", "Attended":"true"},' +
'{"Branch":"Las Vegas", "Department":"Hospitality", "Cost":"20100", "Attended":"false"},' +
'{"Branch":"San Diego", "Department":"Banking", "Cost":"11023", "Attended":"true"}]'

解析将返回 arr[0] 作为 Corporate 对象,arr[1] 作为 Las Vegas 对象等。遍历我得到的属性:

var obj:Object = dp.getItemAt(0);
for (var prop:String in obj) {
trace(prop + ' is ' + obj[prop]);
}

Department is Finance
Attended is true
Branch is Corporate
Cost is 10000

关于string - 我可以在不更改项目顺序的情况下将 JSON 字符串转换为 Flex ArrayCollection 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17362726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com