首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将HTML表格的ndjson转换为json

将HTML表格的ndjson转换为json
EN

Stack Overflow用户
提问于 2020-11-11 14:41:45
回答 1查看 444关注 0票数 0

我想知道是否有可能将这个接口的ndjson数据转换为https://lichess.org/api/team/overberg-chess-group/users,并将其转换为HTML表。我找到了一些javascript代码片段,可以将普通的json转换为html表格,但不能转换为ndjson。任何帮助都将不胜感激

EN

回答 1

Stack Overflow用户

发布于 2020-11-13 06:36:27

看起来API拉出了一个非常接近JSON的文件。假设API数据在var sourceData中,只需要做一些调整……

代码语言:javascript
复制
// 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表中时,您需要将竖线字符"|“转换回换行符...这应该会在你的道路上帮助你..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64781654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档