简体   繁体   English

Uint8Array到JavaScript对象

[英]Uint8Array to JavaScript Object

I am trying to get an object from my AWS S3 bucket with the getObject function however, it seems like it returns a Uint8Array - which is an array of 8-bit unsigned integers . 我试图通过getObject函数从我的AWS S3存储桶中获取一个对象,但是,它似乎返回一个Uint8Array - 这是an array of 8-bit unsigned integers I can't figure out how to convert this back into my object I stored in my S3 bucket. 我无法弄清楚如何将其转换回我存储在S3存储桶中的对象。

Does anybody know how to do this? 有人知道怎么做这个吗?
Thanks. 谢谢。

EDIT: 编辑:

The object looks something like this: 该对象看起来像这样:

awsServices.getObject(core.splitUrlOff(key)).then(object => ({
    key: object.key,
    description: object.description,
    likes: object.likes,
    location: object.location,
    time: object.time,
    uuids: object.uuids,
    views: object.views
}))

This takes an Unit8Array object, converts it to a string then converts that string to an object. 这将获取Unit8Array对象,将其转换为字符串,然后将该字符串转换为对象。

I figured it out. 我想到了。 With tomfa's code found here: BinArraytoJson I simply did: 在这里找到tomfa的代码: BinArraytoJson我只是做了:

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)); 然后: JSON.parse(binArrayToJson(yourBinArray));

This is from my answer: https://stackoverflow.com/a/51659985/7223300 这是我的回答: https//stackoverflow.com/a/51659985/7223300

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM