Javascript 我在React本机应用程序中获取Api时遇到问题
我已经在react native中构建了一个应用程序,所有其他Api都可以顺利获取,但大多数情况下,当我从这个Api方法获取时都会出错。有时,这会给出结果,但大多数情况下会转到错误块。我在邮递员那里测试时得到了结果。 以下是我的提取请求的代码块:-Javascript 我在React本机应用程序中获取Api时遇到问题,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我已经在react native中构建了一个应用程序,所有其他Api都可以顺利获取,但大多数情况下,当我从这个Api方法获取时都会出错。有时,这会给出结果,但大多数情况下会转到错误块。我在邮递员那里测试时得到了结果。 以下是我的提取请求的代码块:- async pagination(collectionId, count) { if (!count) { count = 3; } return new Promise((resolve, reject) => {
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]
产品获取中的错误-[SyntaxError:JSON解析错误:
无法识别的令牌“请同时附加错误我已发布错误消息