我是个新来的土生土长的人.try 制作一些非常简单的应用程序.无法理解如何获取XML数据.有了JSON,一切都清晰简单.
但是如何获取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>
);
},
});