Мне нужна помощь в получении указанных c ключей и их динамических c значений, хранящихся в строке JSON в элементе XML.
Ниже приведен пример данных JSON :
<data attribute-id="item">
[
{
"item_name": "item1",
"quantity": 1,
"key": "subtotal",
"price": {
"currency": "CAD",
"amount": 123.75,
"label": "320.088,75 CAD",
"base": {
"amount": 34.75,
"currency": "USD",
"label": "US$90.75"
}
},
"total": {
"currency": "CAD",
"amount": 123.75,
"label": "320.088,75 CAD",
"base": {
"amount": 90.75,
"currency": "USD",
"label": "US$90.75"
}
},
"included": [
{
"key": "item_price",
"total": {
"currency": "CAD",
"amount": 123,
"label": "376.575,00 CAD",
"base": {
"amount": 106.76,
"currency": "USD",
"label": "US$106.76"
}
},
"price": {
"currency": "CAD",
"amount": 123,
"label": "376.575,00 CAD",
"base": {
"amount": 106.76,
"currency": "USD",
"label": "US$106.76"
}
}
},
{
"key": "rounding",
"total": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
},
"price": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
}
},
{
"key": "item_discount",
"total": {
"currency": "CAD",
"amount": -56486.25,
"label": "-56.486,25 CAD",
"base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
}
},
"price": {
"currency": "CAD",
"amount": -56486.25,
"label": "-56.486,25 CAD",
"base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
}
}
}
]
},
{
"item_name": "item2",
"quantity": 2,
"key": "subtotal",
"price": {
"currency": "CAD",
"amount": 14343.75,
"label": "320.088,75 CAD",
"base": {
"amount": 90.75,
"currency": "USD",
"label": "US$90.75"
}
},
"total": {
"currency": "CAD",
"amount": 3431.5,
"label": "640.177,50 CAD",
"base": {
"amount": 181.5,
"currency": "USD",
"label": "US$181.50"
}
},
"included": [
{
"key": "item_price",
"total": {
"currency": "CAD",
"amount": 753150,
"label": "753.150,00 CAD",
"base": {
"amount": 213.52,
"currency": "USD",
"label": "US$213.52"
}
},
"price": {
"currency": "CAD",
"amount": 376575,
"label": "376.575,00 CAD",
"base": {
"amount": 106.76,
"currency": "USD",
"label": "US$106.76"
}
}
},
{
"key": "rounding",
"total": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
},
"price": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
}
},
{
"key": "item_discount",
"total": {
"currency": "CAD",
"amount": -112972.5,
"label": "-112.972,50 CAD",
"base": {
"amount": -32.02,
"currency": "USD",
"label": "-US$32.02"
}
},
"price": {
"currency": "CAD",
"amount": -56486.25,
"label": "-56.486,25 CAD",
"base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
}
}
}
]
}
]
</data>
Мой ожидаемый вывод - получить ключ "item_name" и его значение Dynami c, а также ключ "amount" и его значение Dynami c (key-> discount (base array)). Ниже приведен ожидаемый результат от данной JSON строки:
"item_name": "item1","base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
},
"item_name": "item2","base": {
"amount": -32.02,
"currency": "USD",
"label": "-US$32.02"
}
Любая помощь очень ценится!