NodeJS Request returning an empty array inside a JSON response

蹲街弑〆低调 提交于 2019-12-11 14:08:02

问题


I am sending a POST JSON request to a URL and it is returning a JSON response. However, the array inside the JSON response is just returning [Object] instead of the Array of JSON elements it should be returning.

Why is this happening?

Ths is my code

var request = require('request');
var requestData = {
        "AERequest":{
            "serviceType":"BE",
            "deviceId": "Test",
            "accountId": "100008288964"
        }
};
const url = "https://ibluatapig.indusind.com/app/uat/balinq/AccountEnquiry?client_id=6867b781-9b21-45c5-9c55-948f7cd1a33f&client_secret=hP3yB3hM2oH4pH4hM1kV3uY8vR3qV7jY8cF6bG2sF5jX8lT1vN";
request({
    url: url,
    method: "POST",
    json: true,
    header: {
        "content-type": "application/json",
    },
    body: requestData
}, function(error, response,body){
    if(!error && response.statusCode === 200){
        console.log(body);l
    } else {
        console.log("error: "+ error);
        console.log("response.statusCode: "+ response.statusCode);
        console.log("response.statusText: "+ response.statusText);
    }
});

And this is the response:

{ AEResponse:
   { status: 'SUCCESS',
     accountID: '100008288964',
     SchmType: '',
     SchmCode: '',
     AcctCurr: 'INR',
     BankId: '',
     Name: '',
     BranchName: '',
     BranchId: '',
     City: '',
     StateProv: '',
     PostalCode: '',
     Country: '',
     AddrType: '',
     Addr1: '',
     Addr2: '',
     Addr3: '',
     AcctBal:
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ] } }

Instead of these object elements, there should have been one array of small JSON objects of 2 elements each.

Any insights on why this would be happening would be much appreciated.

来源:https://stackoverflow.com/questions/48205081/nodejs-request-returning-an-empty-array-inside-a-json-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!