来自fetch的XML响应

时间:2016-09-01 11:05:13

标签: javascript xml react-native fetch

我在反应原生应用中使用fetch。我正在尝试阅读回复,但当我使用alert(response)时,我得到[object Object]。我尝试过其他模块,如xml2js,react-native-html-parser'或xmldom。

fetch(
  /*
       REQUEST CONFIGURATION
  */
}).then(response => {
    console.log(response) // This is what returns [object Object]
  })

2 个答案:

答案 0 :(得分:3)

读取响应主体是一个异步操作,您需要等待承诺首先完成:

fetch(config)
  .then(response => response.text())
  .then(bodyText => {
    // now you have the response body you can parse
  });

另一方面,alert是一个非常钝的调试工具(我甚至不知道它存在于React Native中!)。在“Debug JS Remotely”模式下尝试console.log以获取有关要记录的内容的更多信息。

答案 1 :(得分:1)

处理这样的回复:

createGraphics()
相关问题