我正在使用xml2js节点包来解析xml提要。有什么方法可以防止值被方括号包围?
例如 “参考”:[“ ABC123”] 应该 “ reference”:“ ABC123”
"items": [
{
"reference": ["ABC123"],
"hours": ["35"]
},
{
"reference": ["XYZ123"],
"hours": ["20"]
}
]
答案 0 :(得分:0)
解决方案:
var xml2js = require('xml2js').Parser({explicitArray : false});
产生
"items": [
{
"reference": "ABC123",
"hours": "35"
},
{
"reference": "XYZ123",
"hours": "20"
}
]