1

我正在使用 JSONIX 来编组和解组从其他系统收到的 XML。我要编组和解组的 XML

<charge> 392.2361
<formatted>392.24</formatted>
</charge>

我仍然无法弄清楚如何解组值“392.2361”。有任何想法的人吗?提前致谢

4

2 回答 2

0

您在这里需要的是混合属性

{
    type: 'classInfo',
    localName: 'MyType',
    propertyInfos: [{
        type: 'elementRef',
        name: 'charge',
        elementName: 'formatted',
        collection : true,
        mixed: true
    }]
}

您将获得的价值类似于:

[ '392.2361', { name: { localPart: 'formatted' }, value: '392.24' }]

未经测试,不能保证,但你明白了。

于 2017-12-11T07:24:25.457 回答
0

最后正确应用它。谢谢#lexicore

这是我对混合属性的实现

{
     type: 'classInfo',
     localName: 'ItemizedForDateType', //<date>
     propertyInfos:[
            {
                type: 'element',
                name: 'priceTextType',
                elementName: 'price',
                typeInfo: 'DOTWXML.PriceFormattedType'
            },
            {
                type: 'element',
                name: 'priceMinSellTextType',
                elementName: 'priceMinimumSelling',
                typeInfo: 'DOTWXML.PriceFormattedType'
            }
    ]
},
{
     type: 'classInfo',
     localName: 'PriceFormattedType',                           
     propertyInfos:[
        {
            type: 'elementRef',
            name: 'charge',
            elementName: 'formatted',
            collection : true,
            mixed: true
        },
     ]
}

unmarshall 的结果如下所示:

    "itemizedForDateType": [
      {
        "TYPE_NAME": "DOTWXML.ItemizedForDateType",
        "priceTextType": {
          "TYPE_NAME": "DOTWXML.PriceFormattedType",
          "charge": [
            "236.8738",
            {
              "name": {
                "namespaceURI": "",
                "localPart": "formatted",
                "prefix": "",
                "key": "formatted",
                "string": "formatted"
              },
              "value": "236.87"
            }
          ]
        }
      }
    ]

我通过删除“ collection:true ”犯了一个错误,并且在解组后得到了“ {} ”。一旦我意识到“ collection:true ”是必需的,就把它放在上下文中,一切都被正确地解组了。

于 2017-12-14T04:19:58.510 回答