【发布时间】:2020-03-15 15:49:51
【问题描述】:
我是 React Native 的新手。我在 Firebase 上获取数据,但我想获取它的 JSON 文件。我的 JSON 文件是这样的:enter image description here
如何将 firebase url 更改为我的 php json url? 请帮我 这是我的代码:
return async (dispatch, getState) => {
// any async code you want!
// const userId = getState().auth.userId;
try {
const response = await fetch(
'https://shopapp-f9964.firebaseio.com/products.json'
);
if (!response.ok) {
throw new Error('Something went wrong!');
}
const resData = await response.json();
const loadedProducts = [];
for (const key in resData) {
console.log(resData[key].description);
loadedProducts.push(
new Product(
0,
0,
resData[key].product_image,
resData[key].description,
resData[key].price,
)
);
}
dispatch({
type: SET_PRODUCTS,
products: loadedProducts,
//userProducts: loadedProducts.filter(prod => prod.ownerId === userId)
});
} catch (err) {
// send to custom analytics server
throw err;
}
};
【问题讨论】:
标签: javascript json react-native