簡體   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