简体   繁体   中英

Extract data from API website link using AXIOS (JSON Map Data)

I have the following code:

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 .

Here Is the what I get from the API data:

{
  "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...
  ]
}

I am trying to extract only the ''surrogates'' data, based on an emoji I give it.

For example: "️".

I tried using:

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

But it returns find is not a function .

responsevalue is only JSON ,you can use JSON. parse(responsevalue) and return object,so you can't use find that be long to array

Try console.log(response) in your getResponse function. If it prints undefined then that means that you are not getting response to your webpage. If you are getting response your checkemoji.data.emojiDefinitions is an array so your find should be:

let findemoji = responsevalue.emojiDefinitions.find(post => post.surrogates === myemoji)
        var myemoji = "😀";
    async function getResponse(){
        try {
            let response = await axios.get(`EmojiMap.json`)
            return response.data;
        } catch (error) {
            console.error(error);
        }
    }

    getResponse().then( res => {
        let findemoji = res.emojiDefinitions.find(post => post.surrogates === myemoji) // myemoji = 🖐️
        console.log(findemoji)
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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