简体   繁体   English

使用json2html解析任意json

[英]Parsing arbitrary json with json2html

Does anybody know of detailed api-level docs for json2html? 有人知道json2html的详细api级文档吗? I crawled through their webpage and found very little documentation. 我浏览了他们的网页,发现文档很少。

Basically, I would like to take arbitrary json, and turn it into pretty html much like the "json visualizer" example on the json2html webpage, but the webpage doesn't event state if the visualizer is part of json2html lib or if its something else entirely. 基本上,我想将任意json转换为html2,就像json2html网页上的“ json visualizer”示例一样,但是该网页不会显示该可视化器是否为json2html lib或其他内容的事件完全。

A second question: 第二个问题:

In their example they have the following transform: 在他们的示例中,他们具有以下转换:

var transform = {'tag':'li','html':'${name} (${age})'}; var transform = {'tag':'li','html':'$ {name}($ {age})'};

Which assume I know what the json will have "name" and "age", is there a way to wildcard this and just take pairs in the same form but of any name? 哪一个假设我知道json将具有“ name”和“ age”,有没有办法对此进行通配并仅以相同的形式但对取任何名字?

Actually the library is fairly simple and the complete source code can be found here on github so feel free to pick apart if you like. 实际上,该库相当简单,完整的源代码可以在github上找到,因此,如果您愿意,可以随意拆开。 As for documentation check out the website under examples to get started. 至于文档,请查看示例下的网站以开始使用。

First Question "arbitrary json, and turn it into pretty html much like the "json visualizer" The simple answer is yes, you can visualize unstructured json using json2html. Although the visualizer is not part of the library it was however created using json2html. Have a look at the source code it's all nicely commented and it should give you a good idea on how we created it. 第一个问题是“任意json,然后将其转换成与” html可视化器”非常相似的html 。简单的答案是,您可以使用json2html可视化非结构化的json。尽管该可视化器不是库的一部分,但是它是使用json2html创建的。看一下源代码,它们都被很好地注释了,它应该使您对我们如何创建它有了一个好主意。

Second Question "is there a way to wildcard " Short answer is yes, simply use an inline function 第二个问题“有没有通配符的方法”简短的回答是,只需使用内联函数

 {'tag':'li','html':function() {
    return(this.myWildcardVariable);
 }}

However, since I'm a little confused as to what you're trying to achieve I would say start with the basics (examples) and you'll probably get a better grasp of what the library can do. 但是,由于我对您要实现的目标有些困惑,因此我想从基础知识(示例)入手,您可能会更好地理解库的功能。

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

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