Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am receiving a JSON object as :

http.get(options, function(res) {
    res.on('data', function (chunk) {
        console.log('BODY: ' + chunk);
        var obj = JSON.parse(chunk);
        console.log(sys.inspect(obj));
    });
});

And it prints:

BODY: [{"buck":{"email":"chris@example.com"}}]

but now I'm not able to read anything inside it. How do I get the "email" field?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
163 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...