来自 fetch 的 XML 响应

Fra*_*ios 2 javascript xml fetch react-native

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]
  })
Run Code Online (Sandbox Code Playgroud)

jev*_*lio 7

读取响应体是一个异步操作,需要先等待promise完成:

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

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