JSONIX を使用して、他のシステムから受信した XML をマーシャリングおよびアンマーシャリングしています。マーシャリングおよびアンマーシャリングしたい XML
<charge>
392.2361
<formatted>
392.24</formatted>
</charge>
値「392.2361」を非整列化する方法がまだわかりません。何か考えがある人はいますか?前もって感謝します
JSONIX を使用して、他のシステムから受信した XML をマーシャリングおよびアンマーシャリングしています。マーシャリングおよびアンマーシャリングしたい XML
<charge>
392.2361
<formatted>
392.24</formatted>
</charge>
値「392.2361」を非整列化する方法がまだわかりません。何か考えがある人はいますか?前もって感謝します
最後に適当に貼りました。ありがとう #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」が必要であることに気付いたら、それをコンテキストに入れ、すべてを適切にアンマーシャリングします。
ここで必要なのは混合プロパティです。
{
type: 'classInfo',
localName: 'MyType',
propertyInfos: [{
type: 'elementRef',
name: 'charge',
elementName: 'formatted',
collection : true,
mixed: true
}]
}
値を取得すると、次のようなものになります。
[ '392.2361', { name: { localPart: 'formatted' }, value: '392.24' }]
テストされていません。保証はありませんが、アイデアはわかります。