Upon receiving a Json object from an API, I realized that it contains numerous backslashes and despite passing it through a json validator, it is marked as valid. When using this json object in JavaScript, everything seems to work fine until the final section where I encounter an error. Surprisingly, if someone else follows the same steps with my json string, they might not face any errors:
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\":\"...
let size=Object.size(ResponseJson.data[0].marketPairs)-1;
console.log(size);
alert(typeof(ResponseJson.data[0].marketPairs[0]));
The type of object is correctly identified and its size can be determined without any issue. However, when attempting to extract a specific value from 'marketPairs', an error surfaces:
console.log(ResponseJson.data[0].marketPairs[i].1d_volume);
This results in the following error message:
Uncaught SyntaxError: missing ) after argument list
I am currently unaware of a solution to resolve this issue. Does anyone have any suggestions?
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\",\"volu...
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);
If you view the code snippet above, you will notice that the error persists within it as well.