Converting a Response Buffer to JSON

前端 未结 1 492
甜味超标
甜味超标 2021-01-27 14:47

In AWS, I am issuing a get request through Lambda with the https module. I am able to return the data, but it is in the buffer format when I call callback(null, obj)

1条回答
  •  [愿得一人]
    2021-01-27 15:23

    I figured it out. With tomfa's code found here: BinArraytoJson I simply did:

    var binArrayToJson = function(binArray) {
        var str = "";
        for (var i = 0; i < binArray.length; i++) {
            str += String.fromCharCode(parseInt(binArray[i]));
        } 
        return JSON.parse(str)
    }
    

    Then: JSON.parse(binArrayToJson(yourBinArray));

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