繁体   English   中英

对于HTML表将ndjson转换为json

[英]Convert ndjson to json for HTML table

我想知道是否可以从这个 API 转换 ndjson 数据: https://lichess.org/api/team/overberg-chess-group/users并将其转换为 HTML 表。 我发现了一些 javascript 片段,可以将正常的 json 转换为 html 表,但不能转换 ndjson。 任何帮助,将不胜感激

看起来 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中包含object数据,代表API拉取的ndjson数据。注意,当你go将这个object放入HTML表时,你需要将885302115|"888字符转换回到换行...这应该可以帮助您前进...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM