json - Javascript Object Response - Stack Overflow

I am calling a RESTful web service using the http-https node package. Code below:var request = http.get

I am calling a RESTful web service using the http-https node package. Code below:

var request = http.get(url, function(resp){
   console.log(resp);       
});
request.end();

However, when I examine what is held in the variable resp, it es back as [Object]. When I ask for resp.toString(), I get `[object Object]'. I know that the service is returning me JSON, and I know the structure of the JSON. However, I am unsure why I am getting this response back instead of JSON.

I am calling a RESTful web service using the http-https node package. Code below:

var request = http.get(url, function(resp){
   console.log(resp);       
});
request.end();

However, when I examine what is held in the variable resp, it es back as [Object]. When I ask for resp.toString(), I get `[object Object]'. I know that the service is returning me JSON, and I know the structure of the JSON. However, I am unsure why I am getting this response back instead of JSON.

Share Improve this question asked May 29, 2017 at 17:37 red_studentred_student 3162 gold badges6 silver badges16 bronze badges 3
  • 1 try console.log(JSON.stringify(resp));. Look at headers also for clues as to "why". Note that {}.toString() returns [object Object] ... that is expected – charlietfl Commented May 29, 2017 at 17:41
  • Maybe you getting a direct decoded JSON. – Tyr Commented May 29, 2017 at 17:42
  • Ok I was able to examine the headers, and can confirm that it is 200. However, the res portion has res: [Circular]. This is where I was expecting my JSON to be. Also two other important header fields: 'content-type': 'application/json;charset=UTF-8', 'transfer-encoding': 'chunked'. Would this cause any problems if I am not parsing anything after I get the response? – red_student Commented May 29, 2017 at 20:16
Add a ment  | 

1 Answer 1

Reset to default 1

This might be because,

1)You are getting array [], not the object in response.

2)If you are sure that you are getting object in response, then alert(JSON.stringify(response)) to generate string from response object and also makesure object is non empty.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745162995a4614482.html

相关推荐

  • json - Javascript Object Response - Stack Overflow

    I am calling a RESTful web service using the http-https node package. Code below:var request = http.get

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信