Make json remote in string

2

How can I return the value of a remote json and read it as a string, eg when I get json it prints the entire result as in the image below. codebelow:

varhttps=require('https');varoptionsget={host:'the-evie.com',port:443,path:'/playerscript/pc/Droust',method:'GET'};console.info('Optionsprepared:');console.info(optionsget);console.info('DotheGETcall');varreqGet=https.request(optionsget,function(res){console.log("statusCode: ", res.statusCode);
    res.on('data', function(d) {
        console.info('GET result:\n');
        process.stdout.write(d);
        console.info('\n\nCall completed');
    });
});
reqGet.end();
reqGet.on('error', function(e) {
    console.error(e);
});

What I wanted was to make it filtered such as username, was able to receive value by key, ie key username value Droust.

    
asked by anonymous 19.09.2017 / 07:00

1 answer

2

Convert Json to an object.

var obj = JSON.parse(text);

Then just get the value you want from that object.

var user = obj.username;

In this way your user variable will receive the value Droust.

Read it here too, it may help you: link

    
19.09.2017 / 07:09