Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I was trying this

//...
const getMetadata = async () => {
  try {
    let response = await fetch(
      'https://favradio-stats.glitch.me/metadata'
    );
    let json = await response.json();
    return json;
  } catch (error) {
    console.error(error);
  }
};

console.log(getMetadata);
//...

returns [Function getMetadata]

if I call getMetadata() instead of getMetadata, will get the undesired result:

{"_U": 0, "_V": 0, "_W": null, "_X": null}

Why and what is wrong with that code?

question from:https://stackoverflow.com/questions/65643472/how-do-i-fetch-json-in-react-native

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
180 views
Welcome To Ask or Share your Answers For Others

1 Answer

You could try:

const getMetadata = async () => {
  try {
    let response = await fetch(
      'https://favradio-stats.glitch.me/metadata'
    );
    let json = await response.json();
    return json;
  } catch (error) {
    console.error(error);
  }
}
.then((result) => {
  console.log(result)
});

getMetadata();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...