我正在处理的项目需要对有些复杂的 XML 文件进行大量工作,因此我将它们转换为 SimpleXML 数组,对其进行 JSON 编码并通过 Ajax 将其传递给 Knockout。
问题是几乎每个属性都有属性,SimpleXML 将其塞入一个名为@attributes
. 当我尝试绑定到它时myObject().@attributes.Name
,我得到一个错误
Message: SyntaxError: Unexpected token ILLEGAL;
Bindings value: text: alertObj().@attributes.Name
我已经尝试过'@attributes', ['@attributes'], [@attributes]
,但没有任何效果。我还尝试了各种转义字符和 unicode 转义。
这是json的样子:
var alertObject =
{
"@attributes":
{
"DescriptionContentType":"text\/plain",
"Description":"",
"IsActive":"true",
"Name":"Apache Requests Per Interval"
},
"Frequency":
{
"PeriodInSeconds":"60"
},
"MetricLevelNotification":"false",
"AlertTriggerMode":"2",
"CautionActionDelay":"0",
"DangerActionDelay":"0",
"CautionActionList":
{
"ActionID":
{
"ManagementModuleName":"Base Module",
"ConstructName":"Base SMTP Mail Action"
}
},
"DangerActionList":
{
"ActionID":
{
"ManagementModuleName":"Base Module",
"ConstructName":"Base SMTP Mail Action"
}
},
"MetricGroupingID":
{
"ManagementModuleName":"Base Module",
"ConstructName":"Apache Requests Per Interval"
},
"AlertCombineOperator":"1",
"AlertCompareOperator":"2",
"CautionTargetValue":"2000",
"DangerTargetValue":"15000",
"CautionMinNumPerPeriod":"3",
"CautionAlertPeriod":"6",
"DangerMinNumPerPeriod":"1",
"DangerAlertPeriod":"1"
};
我想避免以任何方式改变结构和名称。
我怎样才能让它工作?