我在工作的陣營原生應用和簡單試圖執行這段代碼XMLParser中給錯誤'無法設置的未定義的屬性值'
fetch('https://ad13.adfarm1.adition.com/banner?sid=3915124&wpt=X.xml')
.then((response) => response.text())
.then((responseJson) => {
console.log("WorkingTillHere",responseJson)
xml_Img = new XMLParser().parseFromString(responseJson); // Assume xmlText contains the example XML
console.log("ParserVideo,",xml_Img);
}) .catch((error) => {
console.log("ParserEx",error);
});
我可以在控制檯窗口中看到
WorkingTillHere
但它不執行XMLParser().parseFromString(responseJson);
和我越來越控制檯日誌
ParserEx TypeError: Cannot set property 'value' of undefined
相同的代碼工作p erfectly好嗎這個URL鏈接fetch('http://teststream.airtango.de/theo/vast.xml')
我想你應該調用異步從http請求中獲取數據, 嘗試添加「等待獲取」並在你的函數前添加異步 –
@GaneshCauda - 爲什麼?在適當的時候調用'.then'鏈 –
我可以在原始XML中看到的唯一區別是它在**的作用**'<![CDATA ['和']]>'在它們自己的行上 - 而在失敗的數據中,您在一行中有'<![CDATA [...等等等等]]> ' - 什麼是XMLParser?它是[這一個](https://www.npmjs.com/package/react-xml-parser)? –