javascript - 我在我的 React Native 应用程序中获取 Api 时遇到问题
问题描述
我已经在 react native 中构建了一个应用程序,所有其他 Api 都可以顺利获取,但是大多数时候我从这个 API 方法获取时都会出错。有时这会给出结果,但大多数时候它会进入错误块。当我在邮递员中测试时,我得到了结果。这是我的获取请求的代码块:-
async pagination(collectionId, count) {
if (!count) {
count = 3;
}
return new Promise((resolve, reject) => {
fetch(AdminUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/graphql',
Authorization: Authorization,
// 'X-Shopify-Storefront-Access-Token': '088879868575'
},
body:
`{
collections(first: 1, query: "id:` +
collectionId +
`") {
edges {
node {
id,
title,
products(first: ` +
count +
`){
edges{
node{
id,
title,
description,
vendor,
tags
variants(first: 1) {
edges {
node {
id
title
price
sku
position
compareAtPrice
barcode
taxable
weight
weightUnit
inventoryQuantity
}
}
}
images(first: 1) {
edges {
node {
id
src
}
}
}
}
cursor
}
}
}
}
}
} `,
})
.then(response => response.json())
.then(responseJson => {
resolve(responseJson);
})
.catch(error => {
alert('error in fetching products by collection11111111111111111');
console.log("error in product fetching - ", error)
reject(error);
});
});},
这是我收到的错误消息:-
error in product fetching - [SyntaxError: JSON Parse error:
Unrecognized token '<']
WARN Possible Unhandled Promise Rejection (id: 1):
SyntaxError: JSON Parse error: Unrecognized token '<'
parse@[native code]
tryCallOne@http://10.0.2.2:8081/index.bundle?
platform=android&dev=true&minify=false:27011:16
http://10.0.2.2:8081/index.bundle?
platform=android&dev=true&minify=false:27112:27
_callTimer@http://10.0.2.2:8081/index.bundle?
platform=android&dev=true&minify=false:31138:17
_callImmediatesPass@http://10.0.2.2:8081/index.bundle?
platform=android&dev=true&minify=false:31174:19
callImmediates@http://10.0.2.2:8081/index.bundle?
platform=android&dev=true&minify=false:31393:33
callImmediates@[native code]
__callImmediates@http://10.0.2.2:8081/index.bundle?
platform=android&dev=true&minify=false:2632:35
http://10.0.2.2:8081/index.bundle?
platform=android&dev=true&minify=false:2409:34
__guard@http://10.0.2.2:8081/index.bundle?
platform=android&dev=true&minify=false:2615:15
flushedQueue@http://10.0.2.2:8081/index.bundle?
platform=android&dev=true&minify=false:2408:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]
解决方案
推荐阅读
- android - Objectbox 另一个 BoxStore 仍然在使用 Dagger 的 Android MVVM 中打开
- python - 如何在 Python 中找到与条件匹配的元素?
- batch-file - 将文件名设置为变量
- javascript - 通过 vuejs 上的按钮重新启动应用程序
- pandas - Pandas 将两列合并为 Json
- java - 无法通过 selenium 和 Java 从 Make My Trip 网站中的返回日期日历中找到任何日期
- swift - 滚动 tableView 时动态更改标签的字体大小
- javascript - 在 JavaScript 中查找和替换不匹配的单词
- unity3d - 统一平台android取消订阅中的Firebase数据库不起作用
- dart - 如何查看已安装的 Flutter 版本?