从 get Storage Amplify 获取对象的 json 数据

Get json data from object from get Storage Amplify

我通过 Amplify 从 S3 存储桶的对象中获取了一些数据。

export function amplify() {
  let key = "68a92d44-f25a-4bd8-9543-cc95369ae9a0";
  return Storage.get(key + ".json", {
    download: true
  })
    .then(function(result) {
      return result;
    })
    .catch(err => console.log(err));
}

结果数据如下所示:

Object { LastModified: Date Tue Nov 12 2019, ETag: "\"(lotsofnumbers)\"", ContentType: "application/json", Metadata: {}, Body: Uint8Array(4168) }

我将如何从该对象获取 JSON 数据?

我试过 result.Body.toString() 给我 JSON 文件及其内容,但我不能写 result.Body.toString().name 或 .meta(我的内容jsonfile),例如,它给了我 "undefined"。我还尝试使用解析将 Uint8Array 转换为 JSON,但出现此错误:"JSON.parse: unexpected character at line 1 column 1 of the JSON data".

这对我有用,不知道哪里出了问题,但现在可以了:)

  var obj = amplify();
        obj.then(async function(result) {
          var json = await new Response(result.Body).json();
          console.log(json.meta);
        });