axios 给了我 JSON 对象,但无法解析为 Javascript 对象

axios gives me JSON object, but can't parse to Javascript object

我一直在想办法解决这个问题,但不知道自己做错了什么。我也是 Aurelia、Typescript 和 Axios 的新手。

后端给了我一个 JSON 个对象数组,我想将其解析为 Javascript 个对象。凉爽的。对于我的假数据,我使用 JSON 占位符。当我解析时,返回的是 [object Object](参见底部图像的 link)。我做错了什么?最终我想提取特定数据,例如 info.name,并显示名称。

test.ts

import axios from 'axios';
const apiURL = 'https://jsonplaceholder.typicode.com/users';

declare var $: any;


export class Test {
    info: string;
    infoX: string;
    public constructor () {
      axios.get(apiURL)
        .then(response => {
          this.info = JSON.stringify(response.data)
          this.infoX = JSON.parse(this.info);
          console.log(this.info);
          console.log(this.infoX);
        })
        .catch(error => console.log(error));
    }
}

test.html

<template>
  <pre style="margin-top: 200px">${info}</pre>
  <pre style="margin-top: 200px">${infoX}</pre>
</template>

screenshot of what the console log and view displays

以下 link 有助于消除我的一些困惑:simple explanation of JSON.parse and JSON.stringify

然后听了Jame在评论中的建议我遍历了数组,并从服务器返回了数据。

test.ts

import axios from 'axios';
const apiURL = 'https://jsonplaceholder.typicode.com/users';

export class Data {
    infos: string;
    public constructor () {
      axios.get(apiURL)
        .then(response => {
          this.infos = response.data;
          console.log(this.infos);
        })
        .catch(error => console.log(error));
    }
}

test.html

<template>
    <ul>
        <li repeat.for="info of infos">
          Name: ${info.name}
        </li>
    </ul>
</template>