1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
6
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7
+ < title > json crack demo</ title >
8
+ < style >
9
+ html {
10
+ height : 100% ;
11
+ }
12
+ body {
13
+ margin : 0 ;
14
+ height : 100% ;
15
+ display : flex;
16
+ flex-direction : column;
17
+ }
18
+ header {
19
+ background-color : # ccc ;
20
+ height : 100px ;
21
+ font-size : 24px ;
22
+ padding : 0 20px ;
23
+ box-sizing : border-box;
24
+ display : flex;
25
+ justify-content : flex-start;
26
+ align-items : center;
27
+ }
28
+ footer {
29
+ background-color : # ccc ;
30
+ height : 50px ;
31
+ }
32
+ .main {
33
+ flex : 1 ;
34
+ display : flex;
35
+ }
36
+ .left {
37
+ background-color : # eee ;
38
+ width : 300px ;
39
+ height : 100% ;
40
+ }
41
+ .left > div {
42
+ height : 50px ;
43
+ line-height : 50px ;
44
+ padding-left : 20px ;
45
+ }
46
+ textarea {
47
+ width : 100% ;
48
+ height : calc (100% - 50px );
49
+ box-sizing : border-box;
50
+ }
51
+ .center {
52
+ flex : 1 ;
53
+ height : 100% ;
54
+ }
55
+ .buttons {
56
+ padding : 20px ;
57
+ }
58
+ .container {
59
+ margin : 20px 100px ;
60
+ background-color : red;
61
+ width : 800px ;
62
+ height : 800px ;
63
+ }
64
+ # jsoncrackEmbed {
65
+ width : 100% ;
66
+ height : 100% ;
67
+ }
68
+ </ style >
69
+ </ head >
70
+ < body >
71
+ < header > json crack demo</ header >
72
+ < div class ="main ">
73
+ < div class ="left ">
74
+ < div > 请输入json</ div >
75
+ < textarea > </ textarea >
76
+ </ div >
77
+ < div class ="center ">
78
+ < ul class ="desc ">
79
+ < li > 1. jsoncrack 独立部署在本地 http://127.0.0.1:5501 下,注意修改,build 后的代码在 jsoncrack.com-2.5.0/out/ 下,不建议使用官方的 jsoncrack.com,有点慢</ li >
80
+ < li > 2. 源码基于 react,在 jsoncrack.com-2.5.0 下,修改后需要打包</ li >
81
+ < li > 3. [不推荐] 方式1:使用load事件载入json</ li >
82
+ < li > 4. [推荐] 方式2:通过get参数传入json,注意替换数据源 https://cdn.jsdelivr.net/gh/csxiaoyaojianxian/
[email protected] /json/test.json
</ li >
83
+ < li > 5. [强烈推荐] 方式3:通过api发送json</ li >
84
+ </ ul >
85
+ < div class ="buttons ">
86
+ < button onclick ="sendToEmbed() "> 通过api更新json</ button >
87
+ </ div >
88
+ < div class ="container ">
89
+ < iframe id ="
jsoncrackEmbed "
src ="
https://jsoncrack.com/widget?json=https://cdn.jsdelivr.net/gh/csxiaoyaojianxian/[email protected] /json/test.json "
frameborder ="
0 "
> </ iframe >
90
+ <!-- <iframe id="jsoncrackEmbed" src="http://127.0.0.1:5501/widget.html?json=https://cdn.jsdelivr.net/gh/csxiaoyaojianxian/[email protected] /json/test.json" frameborder="0"></iframe> -->
91
+ <!-- <iframe id="jsoncrackEmbed" src="http://127.0.0.1:5501/widget.html" frameborder="0"></iframe> -->
92
+ </ div >
93
+ </ div >
94
+ </ div >
95
+ < script >
96
+ // [不推荐] 方式1:使用load事件载入json
97
+ /*
98
+ const jsonCrackEmbed = document.querySelector("iframe");
99
+ const json = JSON.stringify({
100
+ "section": "It loaded!"
101
+ });
102
+ jsonCrackEmbed?.addEventListener("load", () => {
103
+ setTimeout(() => jsonCrackEmbed.contentWindow.postMessage({
104
+ json
105
+ }, "*"), 500);
106
+ });
107
+ */
108
+
109
+ // [推荐] 方式2:通过get参数传入json
110
+
111
+ // [推荐] 方式3:通过api发送json
112
+ function sendToEmbed ( ) {
113
+ const jsonCrackEmbed = document . getElementById ( "jsoncrackEmbed" ) ;
114
+ const json = JSON . stringify ( {
115
+ name : 'csxiaoyao.com' ,
116
+
117
+ list : [ {
118
+ test : 1 ,
119
+ } ] ,
120
+ } ) ;
121
+ const options = {
122
+ theme : "light" , // "light" or "dark"
123
+ direction : "RIGHT" , // "UP", "DOWN", "LEFT", "RIGHT"
124
+ } ;
125
+ jsonCrackEmbed . contentWindow . postMessage ( {
126
+ json,
127
+ options
128
+ } , "*" ) ;
129
+ }
130
+ </ script >
131
+ < footer > </ footer >
132
+ </ body >
133
+ </ html >
0 commit comments