Node.js: Parse JSON object

前端 未结 1 393
礼貌的吻别
礼貌的吻别 2020-12-13 10:23

I am receiving a JSON object as :

http.get(options, function(res) {
    res.on(\'data\', function (chunk) {
        console.log(\'BODY: \' + chunk);
                 


        
1条回答
  •  醉梦人生
    2020-12-13 10:29

    You should be doing something along the lines of:

    http.get(options, function(res){
        var data = '';
    
        res.on('data', function (chunk){
            data += chunk;
        });
    
        res.on('end',function(){
            var obj = JSON.parse(data);
            console.log( obj.buck.email );
        })
    
    });
    

    If im not mistaken.

    0 讨论(0)
提交回复
热议问题