在此先感谢您的帮助。我正在 java 中的 testng 上使用 rest assured 测试 GRAPHQL API。
我正在尝试发送伪装成 JSON 的 agraphQL 对象作为帖子,但是当尝试将字符串打包为 JSON 对象时,我收到以下错误:
SyntaxError: Unexpected token B<br> at Object.parse (native)<br> at parse (/app/node_modules/body-parser/lib/types/json.js:88:17)<br> at /app/node_modules/body-parser/lib/read.js:116:18<br> at invokeCallback (/app/node_modules/raw-body/index.js:262:16)<br> at done (/app/node_modules/raw-body/index.js:251:7)<br> at IncomingMessage.onEnd (/app/node_modules/raw-body/index.js:307:7)<br> at emitNone (events.js:80:13)<br> at IncomingMessage.emit (events.js:179:7)<br> at endReadableNT (_stream_readable.js:913:12)<br> at _combinedTickCallback (internal/process/next_tick.js:74:11)<br> at process._tickDomainCallback (internal/process/next_tick.js:122:9)
我要创建的 JSON 对象在这里:
"{\"query\":\"{marketBySlug(slug: \"Boston\") {countryCode}}\"}"
我发现我的问题是将 Boston 标识为字符串的转义引号破坏了内部构造的 Graphql 查询字符串,但我不确定如何解决这个问题。
最佳答案
试试这个:
"{\"query\":\"{marketBySlug(slug: \\\"Boston\\\") {countryCode}}\"}"
关于java - 将 Graphql 查询作为 JSON 字符串传递时收到意外 token 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39550733/