使用AXIOS从API网站链接中提取数据(JSON映射数据)

我有以下代码:

    let getResponse = async () => {
    let checkemoji = await axios.get(`https://somewebsite.com/misc/EmojiMap.json`)
    let response = checkemoji.data
    return response
    }
    let responsevalue = await getResponse()
    let findemoji = responsevalue.emojiDefinitions.surrogates
    console.log(findemoji)

checkemoji.data.emojiDefinitions returns as undefined.

这是我从API数据中获得的信息:

{
  "version": "1574367168751",
  "versionTimestamp": "2019-11-21T20:12:48.7512821+00:00",
  "emojiDefinitions": [
    {
      "primaryName": "grinning",
      "primaryNameWithColons": ":grinning:",
      "names": [
        "grinning"
      ],
      "namesWithColons": [
        ":grinning:"
      ],
      "surrogates": "😀",
      "utf32codepoints": [
        128512
      ],
      "assetFileName": "7c010dc6da25c012643ea22c1f002bb4.svg",
      "assetUrl": "https://discordapp.com/assets/7c010dc6da25c012643ea22c1f002bb4.svg"
    },
    etc...
  ]
}

我试图根据我提供的表情符号仅提取“代理”数据。

例如:“🖐️”。

我尝试使用:

 let findemoji = responsevalue.find(post => post.emojiDefinitions.surrogates === myemoji) // myemoji = 🖐️

But it returns find is not a function.

评论
  • vvelit
    vvelit 回复

    在您的getResponse函数中尝试console.log(response)。如果打印未定义,则表示您未获得对网页的响应。如果得到响应,则checkemoji.data.emojiDefinitions是一个数组,因此您应该找到:

    let findemoji = responsevalue.emojiDefinitions.find(post => post.surrogates === myemoji)