Обход сложного Json Jquery
Всем привет. Ребята подскажите пожалуйста как разобрать массив в Json. Вывести так же в тегах <br>
{"$id":"1","id":34,"dateTimeAdd":"2021-12-11T16:45:12.0015098","cash":70,"listCoinsChanges":{"$id":"2","$values":[{"$id":"3","id":52,"cost":10.00,"quantity":2,"order":{"$ref":"1"}}]},"productId":9,"product":null}
![]()
$(document).ready(function () {
$('#buttonCash').click(function () {
$.ajax({
type: 'GET',
url: '/user/GetChange',
success: function (result) {
var s = 'Id: ' + result.id;
s += '<br>total :' + result.cash;
$('#resultcash').html(s);
}
});
});
});
Мой код. Никак не могу получить то что находится в listCoinsChanges а именно Cost и quantity |
BorisJe,
<pre id="out"></pre>
<script>
let obj =
{
"$id": "1", "id": 34, "dateTimeAdd": "2021-12-11T16:45:12.0015098", "cash": 70, "listCoinsChanges":
{
"$id": "2", "$values":[
{
"$id": "3", "id": 52, "cost": 10.00, "quantity": 2, "order":
{
"$ref": "1"
}
}
]
}
, "productId": 9, "product": null
} ;
let arr = obj.listCoinsChanges.$values;
out.append(JSON.stringify(arr, "", 1));
out.append(`\n cost : ${arr[0].cost}`);
out.append(`\n quantity : ${arr[0].quantity}`);
</script>
|
Цитата:
|
$.each(result.listCoinsChanges.$values,function(index, value) {
s += '<br> Количество :' + value.quantity;
s += '<br> номинал :' + value.cost;
count++;
});
$('#result3').html(s);
|
| Часовой пояс GMT +3, время: 10:56. |