My goal is to iterate through JSON data and extract "time", "blocks" information, while filtering the "amounts" based on a specific variable named _miner.
So far, I've successfully retrieved the name, time, and blocks data, but I'm struggling with properly filtering the final amounts for a specific addr. Once this is done, I plan to display the results in a table to present them to the user.
[
{
"name":"zelcash",
"pending":{
"blocks":[
],
"confirms":{
}
},
"payments":[
{
"time":1531601680340,
"txid":"de12e0a3a0d75df7f9d5da6e78896ec5f6d72c0063df8d059b90d66a6aa0d535",
"shares":3386.04739737,
"paid":149.85034477,
"miners":2,
"blocks":[
119148
],
"amounts":{
"t1XHpNtYY2N3EMDRoX9RM2hq4DWWPZSmawJ":94.69254759,
"t1ZsrJASHjvSU8mcLA4K1KuBYESMpXQgwpM":55.15779718
},
"balances":{
},
"work":{
"t1XHpNtYY2N3EMDRoX9RM2hq4DWWPZSmawJ":2139.69113513,
"t1ZsrJASHjvSU8mcLA4K1KuBYESMpXQgwpM":1246.35626224
}
},
// More payment entries...
]
}
]
Ajax/JS
$.ajax({
url: "https://xxxxxx/api/payments",
dataType: 'json',
success: function (data) {
var _miner = "t1XHpNtYY2N3EMDRoX9RM2hq4DWWPZSmawJ";
var addr = _miner;
for (var i = 0; i < data.length; i++) {
console.log(data[i].name);
var payments = data[i].payments;
for (var j = 0; j < payments.length; j++) {
var blocks = payments[j].blocks;
for (var b = 0; b < blocks.length; b++) {
//console.log(blocks[b])
}
console.log(payments[j].amounts);
}
}
},
error: function() {
//alert("Was unable to get info!");
}
});
I want the console output to look like this so I can later format it into a table:
zelcash
1531601680340
94.69254759
zelcash
1531599760228
94.33175716
//repeat