XML2JS删除方括号周围的值

时间:2020-02-12 17:42:15

标签: javascript node.js json xml2js

我正在使用xml2js节点包来解析xml提要。有什么方法可以防止值被方括号包围?

例如 “参考”:[“ ABC123”] 应该 “ reference”:“ ABC123”

"items": [
    {
        "reference": ["ABC123"],
        "hours": ["35"]
    },
    {
        "reference": ["XYZ123"],
        "hours": ["20"]
    }
]

1 个答案:

答案 0 :(得分:0)

解决方案:

var xml2js = require('xml2js').Parser({explicitArray : false});

产生

"items": [
    {
        "reference": "ABC123",
        "hours": "35"
    },
    {
        "reference": "XYZ123",
        "hours": "20"
    }
]