【发布时间】:2016-05-16 17:44:11
【问题描述】:
我正在通过react-native 开发一个移动应用程序,我必须调用一个返回XML 的odata 服务,并且我需要将其转换为json 对象。
我该怎么做?
return fetch(url, {
method: 'GET',
headers: {
Authorization: config.api.auth,
},
})
.then(response => response.json())
// .then(response => response.text())
// .then(xml => _xmlToJson(xml))
.then(json => dosomething(json))
.catch(ex => showError(ex));
};
我试图获取text() 而不是json() 并将其传递给另一个方法,该方法将xml 转换为json 但问题是该方法需要xml object 但text() 返回字符串,我在react-native 中找不到将string 转换为xml 的方法。
附言由于 React Native 使用 JavaScriptCore,它只是一个 javascript 解释器,所以没有 Browser Object Model,没有文档对象,没有窗口等可以使用
【问题讨论】:
标签: json xml react-native