Newbie Question. How do I get this format ot display?
Newbie Question. How do I get this format ot display?

I have been trying for a week to log into my API with username and password via ajax/GET etc without any success. However, I have managed to download and save the information with curl and save it to a text file. The format is (from their site)
{"success":true,"balances":{"BTC":"13.00419483","XMR":"396.93688709","LTC":"2.00000000","SUMO":"1.00000000","ETN":"0.10000000","AEON":"0.00000000","XVG":"1.00000000","BCN":"2.20000000","FBF":"1.00000000","XAO":"2.00000000","ITNS":"20.00000000"}}
I have managed to get the file to load and I can see in console.log that the info has loaded, but it will not load to the table. The error is
XML Parsing Error: not well-formed
Location: file:///F:/Test/working/balances.txt
Line Number 1, Column 1: balances.txt:1:1
balances: Object { BTC: "0.00000000", XMR: "0.00000000", LTC: "0.00000000", … }
So, I guess it doesn't like that format? The code I have is
$(document).ready( function () {
var table = $('#balances').DataTable({
columns: [
{ data: 'success' },
{ data: 'balances'}
]
});
$.getJSON("balances.txt", function(data) {
console.log(data)
var dt_data = [];
for (var i=0; i<data.length; i++) {
var trade_name = Object.keys(data[i])[0];
console.log("trade Name" + trade_name)
var trades = data[i][trade_name];
trades.name = trade_name;
dt_data.push(trades);
}
console.log(dt_data)
table.rows.add( dt_data ).draw();
});
} );
I have tried with the codeyou gave me for the other table removed with the same result.
How can I get the data to display?
Thank you
Answers
This is your data here:
If you want a two-column table, you would need the data to look like:
See example here. You would need to also set
ajax.dataSrc
to bebalances
,Colin
Thank you Colin for the reply
I am obviously missing something fundametntal as it just won't work for me. The example works, but not with my file. My new code, after trying many variants is
but I get the same error(s)
etc,etc. So the file is loading, The datatable says "no data available in table"
What am I missing??
Thank you
I would add that the example data files all have [ ] square brackets in them but my data file does not. Is that an indication of what needs doing?
After much Googling and trial & error, I have the correct result displayed. It needed to have the data converted to an array to include the [ ] In case it helps anyone the code is
However, I still get the error in the console log
I would like to know how to clear it in case it causes problems down the line..
Thanks
Glad working. The error isn't from DataTables I'm afraid, so I can't help you with that,
Colin
Thank you for your help it is appreciated