我想知道是否有可能将这个接口的ndjson数据转换为https://lichess.org/api/team/overberg-chess-group/users,并将其转换为HTML表。我找到了一些javascript代码片段,可以将普通的json转换为html表格,但不能转换为ndjson。任何帮助都将不胜感激
发布于 2020-11-13 06:36:27
看起来API拉出了一个非常接近JSON的文件。假设API数据在var sourceData中,只需要做一些调整……
// Add commas between the list of objects...
data = sourceData.split( '}\n{' ).join( '},{' );
// ...remove all carriage return line feeds...
data = data.split( '\r\n' ).join( '|' );
// ...and there's one instance of a double quoted string,
// eg, "bio":""I am committed..."". This appears to be
// the only occurrence of this anomaly, so the following
// currently works, but you might run into issues in the
// future, for example, if an attribute is a null string "".
data = data.split( '""' ).join( '"' );
let dataObject = JSON.parse( '[' + data + ']' );此时,dataObject包含了对象数据,表示通过接口拉取的ndjson数据。请注意,当您要将此对象放入HTML表中时,您需要将竖线字符"|“转换回换行符...这应该会在你的道路上帮助你..。
https://stackoverflow.com/questions/64781654
复制相似问题