我正在尝试 Lichess API。我正在尝试导出用户的游戏。根据文档,我可以收到 PGN 或 ndjson 作为响应。
现在这不起作用:
const api_url = "https://lichess.org/api/games/user/Terinieks?max=5&since=1578607200000&perfType=bullet"
async function getData() {
let response = await fetch(api_url, {
headers: {
"Accept": "application/x-ndjson"
}
});
let data = await response.json();
}
getData()
我正在努力寻找如何await response.json()
工作。
因为据我了解,我现在需要以某种方式将我的响应(在 ndjson 中)转换为 json,但是如何?
更新 1
我正在尝试使用NPM 包 'can-ndjson-stream',这是从文章中建议的:Streaming Data with Fetch() and NDJSON
在 app.js 我有import ndjsonStream from "can-ndjson-stream";
,但我得到错误:
module "c:/Users/Juris/Desktop/Chess Stats/node_modules/can-ndjson-stream/can-ndjson-stream"
Could not find a declaration file for module 'can-ndjson-stream'.
'c:/Users/Juris/Desktop/Chess Stats/node_modules/can-ndjson-stream/
can-ndjson-stream.js' implicitly has an 'any' type.
Try npm install @types/can-ndjson-stream if it exists
or add a new declaration (.d.ts) file containing
declare module 'can-ndjson-stream';ts(7016)
在 Chrome 中这个错误:
Uncaught TypeError: Failed to resolve module specifier "can-ndjson-stream". Relative references must start with either "/", "./", or "../".
index.html 有<script type="module" src="JS/app.js"></script>
不确定如何让 import 语句正常工作。