Joshsdasdasdasdasd
Member
So I currently have some code that loads data from an API using the http.simpleRequest method. When I check the data on the API manually, I get something like this:
{"status":"ok","meta":{"count":2},"data":[{"nickname":"foo","account_id":999999999},{"nickname":"bar","account_id":000000000}]}
I assume this to be something that I could easily use JSON.parse on, but that doesn't seem to yield the desired result.
Here is relevant parts of code that are yielding unexpected results.
This is the JSON.parse error -> Unexpected token u in JSON at position 0 Stack trace: SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>)
and this is the engine.log(clientInfoResponse) -> {"data":{},"headers":{"Access-Control-Allow-Origin":["*"],"Access-Control-Request-Method":["GET, POST"],"Connection":["keep-alive"],"Content-Language":["en"],"Content-Length":["148"],"Content-Type":["application/json; charset=utf-8"],"Date":["Mon, 25 Feb 2019 05:08:20 GMT"],"Etag":["\"a172cdf798e4f724b2d0d9464c458ac8\""],"Server":["nginx"],"X-Api-Version":["2.65.0"]},"status":"200 OK","statusCode":200}
I'm sure I am missing something obvious but I am at a loss. Off to bed, look forward to seeing responses in the morning!
{"status":"ok","meta":{"count":2},"data":[{"nickname":"foo","account_id":999999999},{"nickname":"bar","account_id":000000000}]}
I assume this to be something that I could easily use JSON.parse on, but that doesn't seem to yield the desired result.
Here is relevant parts of code that are yielding unexpected results.
JavaScript:
function setClientWN8() {
backend.getClients().forEach(client => {
var nameClient = client.name();
var clientResponse;
engine.log(nameClient);
var urlCheck=apiURL+region+'/wot/account/list/'+apikey+'&search='+nameClient;
engine.log(urlCheck);
var clientFound=getClientInfo(urlCheck);
engine.log(clientFound);
if (clientFound["meta"]["count"]!=0) { //<-clientFound.meta is undefined w/o jsonparse
//irrelevant for rest of this function, skipping to other function
function getClientInfo(url){
http.simpleRequest({
method: 'GET',
timeout: 60000,
url: url
},
function (error, clientInfoResponse) {
engine.log(clientInfoResponse);//this does not look as expected, see below
clientInfo=JSON.parse(clientInfoResponse);//this errors
return clientInfo;
});
This is the JSON.parse error -> Unexpected token u in JSON at position 0 Stack trace: SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse (<anonymous>)
and this is the engine.log(clientInfoResponse) -> {"data":{},"headers":{"Access-Control-Allow-Origin":["*"],"Access-Control-Request-Method":["GET, POST"],"Connection":["keep-alive"],"Content-Language":["en"],"Content-Length":["148"],"Content-Type":["application/json; charset=utf-8"],"Date":["Mon, 25 Feb 2019 05:08:20 GMT"],"Etag":["\"a172cdf798e4f724b2d0d9464c458ac8\""],"Server":["nginx"],"X-Api-Version":["2.65.0"]},"status":"200 OK","statusCode":200}
I'm sure I am missing something obvious but I am at a loss. Off to bed, look forward to seeing responses in the morning!