I have a Json object which i get from a API, so i can not change it and need to work with it like it is. I see it have a lot of backlashes but if i put the json string into a json validator i get the info its vallid.
if i use the json object in javascript i also can read it until the last part where i get a error, when you take my json string and you do the following steps, you will see no error message:
let ResponseJson = {"config":{"data":"market-pairs","limit":1,"symbol":"'LTC'","page":0},"usage":{"day":112,"month":262},"data":[{"name":"Litecoin","symbol":"LTC","total_rows":2221,"marketPairs":[{"id":83223,"asset_id":4,"exchange_id":113,"unique_key":"4:citex:LTC:USDT","1d":"{\"volume\":\"196939102.19\",\"volume_base\":\"1119444.67\",\"volume_change\":\"-29686113.31\",\"volume_base_change\":\"-142615.38\",\"price_change\":\"4.71070407\",\"price_quote_change\":\"4.26000000\"}","1d_volume":196939102.19,"1d_trades":null,"30d":"{\"volume\":\"10993069419.34\",\"volume_base\":\"46739211.09\",\"volume_change\":\"-111703700.37\",\"volume_base_change\":\"6038573.46\",\"price_change\":\"-173.96929593\",\"price_quote_change\":\"-174.42000000\"}","30d_volume":10993069419.34,"30d_trades":null,"exchange":"citex","from_symbol":"LTC","to_symbol":"USDT","price":178.270704,"type":"spot","last_updated":1622999998,"name":"Citex","exchange_lunar_id":"citex","pairing_url":"https://trade.citex.co.kr/trade/{{symbol1}}_{{symbol2}}","market_sort":"LTC_USDT","logo":"https://dkhpfm5hits1w.cloudfront.net/exchanges/citex.png"}]}]}
let size=Object.size(ResponseJson.data[0].marketPairs)-1;
console.log(size);
alert(typeof(ResponseJson.data[0].marketPairs[0]));
it will say you its a object and you can read also the size. But now if i try to read the value from marketPairs:
console.log(ResponseJson.data[0].marketPairs[i].1d_volume);
then i get the error message:
Uncaught SyntaxError: missing ) after argument list
i dont know currently how to slove this, have somebody a idea?
Object.size = function(obj) {
var size = 0,
key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
let ResponseJson = {"config":{"data":"market-pairs","limit":1,"symbol":"'LTC'","page":0},"usage":{"day":112,"month":262},"data":[{"name":"Litecoin","symbol":"LTC","total_rows":2221,"marketPairs":[{"id":83223,"asset_id":4,"exchange_id":113,"unique_key":"4:citex:LTC:USDT","1d":"{\"volume\":\"196939102.19\",\"volume_base\":\"1119444.67\",\"volume_change\":\"-29686113.31\",\"volume_base_change\":\"-142615.38\",\"price_change\":\"4.71070407\",\"price_quote_change\":\"4.26000000\"}","1d_volume":196939102.19,"1d_trades":null,"30d":"{\"volume\":\"10993069419.34\",\"volume_base\":\"46739211.09\",\"volume_change\":\"-111703700.37\",\"volume_base_change\":\"6038573.46\",\"price_change\":\"-173.96929593\",\"price_quote_change\":\"-174.42000000\"}","30d_volume":10993069419.34,"30d_trades":null,"exchange":"citex","from_symbol":"LTC","to_symbol":"USDT","price":178.270704,"type":"spot","last_updated":1622999998,"name":"Citex","exchange_lunar_id":"citex","pairing_url":"https://trade.citex.co.kr/trade/{{symbol1}}_{{symbol2}}","market_sort":"LTC_USDT","logo":"https://dkhpfm5hits1w.cloudfront.net/exchanges/citex.png"}]}]}
let size=Object.size(ResponseJson.data[0].marketPairs)-1;
console.log(size);
alert(typeof(ResponseJson.data[0].marketPairs[0]));
console.log(ResponseJson.data[0].marketPairs[i].1d_volume);
here is the code in a snippet, you can see the error happen there also