我是React-Native的新手。试图制作一些非常简单的应用程序。无法弄清楚如何获取XML数据。使用JSON,一切都很简单明了。React-Native提取XML数据
但是如何获取XML?试图通过this和一些其他类似的脚本将其转换为JSON,但没有任何成功。需要帮助:/
我的代码看起来很简单:
var xml_url = 'http://api.example.com/public/all.xml';
var ExampleProject = React.createClass({
getInitialState: function() {
return {
data: {results:{}},
};
},
componentDidMount: function() {
this.fetchData();
},
fetchData: function() {
fetch(xml_url)
.then((response) => response.json())
.then((responseData) => {
this.setState({
data: responseData.data,
});
})
.done();
},
render: function() {
return (
<View style={styles.wrapper}>
<View style={styles.container}>
<View style={styles.box}>
<Text style={styles.heading}>Heading</Text>
<Text>Some text</Text>
</View>
</View>
</View>
);
},
});
尝试使用'response.text()' – potench
对此的任何答案?我遇到了同样的问题。那里没有纯粹的JS XML解析器吗? – nicholas