-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcjson-file-format-problem.html
660 lines (571 loc) · 33.4 KB
/
cjson-file-format-problem.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
<!DOCTYPE html><html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="hexo-theme" content="https://github.com/xaoxuu/hexo-theme-stellar/tree/1.29.1" theme-name="Stellar" theme-version="1.29.1">
<meta name="generator" content="Hexo 7.3.0">
<meta http-equiv='x-dns-prefetch-control' content='on' />
<meta name="renderer" content="webkit">
<meta name="force-rendering" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="HandheldFriendly" content="True" >
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#000">
<meta name="theme-color" content="#f9fafb">
<title>cJson数据格式问题 - hywing's blog</title>
<meta name="description" content="Bug解决">
<meta property="og:type" content="article">
<meta property="og:title" content="cJson数据格式问题">
<meta property="og:url" content="https://blog.hywing.cn/cjson-file-format-problem.html">
<meta property="og:site_name" content="hywing's blog">
<meta property="og:description" content="Bug解决">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2025-02-12T16:00:00.000Z">
<meta property="article:modified_time" content="2025-02-16T13:38:50.846Z">
<meta property="article:author" content="hywing">
<meta property="article:tag" content="linux">
<meta property="article:tag" content="Windows">
<meta property="article:tag" content="cJson">
<meta name="twitter:card" content="summary">
<meta name="keywords" content="linux,Windows,cJson">
<!-- feed -->
<link rel="stylesheet" href="/css/main.css?v=1.29.1">
<link rel="shortcut icon" href="/img/logo.jpg">
<link rel="stylesheet" href="https://cdn.staticfile.org/lxgw-wenkai-screen-webfont/1.6.0/lxgwwenkaiscreen.css"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome-animation@0.2.1/dist/font-awesome-animation.min.css">
</head>
<body>
<div class="l_body s:aa content tech" id="start" layout="post" ><aside class="l_left"><div class="leftbar-container">
<header class="header"><div class="logo-wrap"><a class="avatar" href="/about/"><div class="bg" style="opacity:0;background-image:url(https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/avatar/round/rainbow64@3x.webp);"></div><img no-lazy class="avatar" src="/img/avatar.jpg" onerror="javascript:this.classList.add('error');this.src='https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/image/2659360.svg';"></a><a class="title" href="/"><div class="main" ff="title">hywing's blog</div><div class="sub normal cap">江上往来人,但爱鲈鱼美</div><div class="sub hover cap" style="opacity:0"> 君看一叶舟,出没风波里</div></a></div></header>
<div class="nav-area">
<div class="search-wrapper" id="search-wrapper"><form class="search-form"><a class="search-button" onclick="document.getElementById("search-input").focus();"><svg t="1705074644177" viewBox="0 0 1025 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1560" width="200" height="200"><path d="M1008.839137 935.96571L792.364903 719.491476a56.783488 56.783488 0 0 0-80.152866 0 358.53545 358.53545 0 1 1 100.857314-335.166073 362.840335 362.840335 0 0 1-3.689902 170.145468 51.248635 51.248635 0 1 0 99.217358 26.444296 462.057693 462.057693 0 1 0-158.255785 242.303546l185.930047 185.725053a51.248635 51.248635 0 0 0 72.568068 0 51.248635 51.248635 0 0 0 0-72.978056z" p-id="1561"></path><path d="M616.479587 615.969233a50.428657 50.428657 0 0 0-61.498362-5.534852 174.655348 174.655348 0 0 1-177.525271 3.484907 49.403684 49.403684 0 0 0-58.833433 6.76482l-3.074918 2.869923a49.403684 49.403684 0 0 0 8.609771 78.10292 277.767601 277.767601 0 0 0 286.992355-5.739847 49.403684 49.403684 0 0 0 8.404776-76.667958z" p-id="1562"></path></svg></a><input type="text" class="search-input" id="search-input" placeholder="站内搜索"></form><div id="search-result"></div><div class="search-no-result">没有找到内容!</div></div>
<nav class="menu dis-select"><a class="nav-item active" title="博客" target="_blank" rel="noopener" href="https://github.com/hywing"><img no-lazy src="/img/git.jpg" / onerror="javascript:this.classList.add('error');this.src='https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/image/2659360.svg';"></a><a class="nav-item" title="文档" href="/wiki"><img no-lazy src="/img/wiki.png" / onerror="javascript:this.classList.add('error');this.src='https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/image/2659360.svg';"></a><a class="nav-item" title="自动化" target="_blank" rel="noopener" href="https://autostuff.net" style="color:#FA6400"><img no-lazy src="/img/autostuff.png" / onerror="javascript:this.classList.add('error');this.src='https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/image/2659360.svg';"></a><a class="nav-item" title="作者" target="_blank" rel="noopener" href="https://post.hywing.cn/about/" style="color:#F44336"><img no-lazy src="/img/heaven.jpg" / onerror="javascript:this.classList.add('error');this.src='https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/image/2659360.svg';"></a></nav>
</div>
<div class="widgets">
<widget class="widget-wrapper post-list"><div class="widget-header dis-select"><span class="name">最近更新</span></div><div class="widget-body fs14"><a class="item title" href="/auto-parts-stage.html"><span class="title">汽车零部件研发的各个阶段</span></a><a class="item title" href="/project-overview-specification.html"><span class="title">项目概要设计说明书</span></a><a class="item title" href="/ubuntu22.04-install-ros2.html"><span class="title">Ubuntu22.04搭建ROS2运行环境</span></a><a class="item title" href="/csv-file-lose-precision.html"><span class="title">解决csv文件导出时间戳精度丢失的问题</span></a><a class="item title" href="/windows-program-chinese-path-problem.html"><span class="title">Windows程序读取不了中文路径问题</span></a><a class="item title" href="/long-data-size.html"><span class="title">long数据类型跨平台问题</span></a><a class="item title" href="/git-clone-url-too-long.html"><span class="title">Windows平台git clone文件路径太长报错</span></a><a class="item title" href="/ros2-foxy-subscribe-problem.html"><span class="title">ros2 foxy订阅话题问题</span></a><a class="item title" href="/embedded-code-optimization.html"><span class="title">嵌入式代码优化技巧</span></a><a class="item title" href="/complile-mode.html"><span class="title">各种编译模式的区别</span></a></div></widget>
</div>
<footer class="footer dis-select"><div class="social-wrap"><a class="social" title="Github" href="/" rel="noopener noreferrer"><i class="fa-solid fa-github fa-brands fa-bounce"></i></a><a class="social" href="/" rel="noopener noreferrer"><i class="fa fa-wrench faa-wrench animated faa-fast"></i></a><a class="social" href="/" rel="noopener noreferrer"><i class="fas fa-spinner fa-pulse"></i></a><a class="social" href="/" rel="noopener noreferrer"><i class="fas fa-cog fa-spin"></i></a><a class="social" onclick="switchTheme()"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><path fill="currentColor" fill-rule="evenodd" d="M582.4 326.4c-140.8 0-256 115.2-256 256s115.2 256 256 256 256-115.2 256-256-115.2-256-256-256z m0 448c-70.4 0-131.2-36.8-164.8-92.8 12.8 3.2 27.2 4.8 40 4.8 121.6 0 219.2-99.2 219.2-219.2 0-17.6-1.6-35.2-6.4-52.8 60.8 32 102.4 96 102.4 169.6 1.6 104-84.8 190.4-190.4 190.4zM582.4 262.4c17.6 0 32-14.4 32-32v-128c0-17.6-14.4-32-32-32s-32 14.4-32 32v128c0 17.6 14.4 32 32 32zM262.4 582.4c0-17.6-14.4-32-32-32h-128c-17.6 0-32 14.4-32 32s14.4 32 32 32h128c17.6 0 32-14.4 32-32zM310.4 356.8c6.4 6.4 14.4 9.6 22.4 9.6 8 0 16-3.2 22.4-9.6 12.8-12.8 12.8-32 0-44.8l-91.2-91.2c-12.8-12.8-32-12.8-44.8 0-12.8 12.8-12.8 32 0 44.8l91.2 91.2zM944 220.8c-12.8-12.8-32-12.8-44.8 0l-91.2 91.2c-12.8 12.8-12.8 32 0 44.8 6.4 6.4 14.4 9.6 22.4 9.6 8 0 16-3.2 22.4-9.6l91.2-91.2c12.8-12.8 12.8-33.6 0-44.8zM310.4 808l-91.2 91.2c-12.8 12.8-12.8 32 0 44.8 6.4 6.4 14.4 9.6 22.4 9.6 8 0 16-3.2 22.4-9.6l91.2-91.2c12.8-12.8 12.8-32 0-44.8-11.2-11.2-32-11.2-44.8 0z"></path></svg></a></div></footer>
</div></aside><div class="l_main" id="main">
<div class="article banner top">
<div class="content">
<div class="top bread-nav footnote"><div class="left"><div class="flex-row" id="breadcrumb"><a class="cap breadcrumb" href="/">主页</a>
<span class="sep"></span><a class="cap breadcrumb" href="/">文章</a><span class="sep"></span><a class="cap breadcrumb-link" href="/categories/%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1/">程序设计</a></div>
<div class="flex-row" id="post-meta"><span class="text created">发布于:<time datetime="2025-02-12T16:00:00.000Z">2025-02-13</time></span><span class="sep updated"></span><span class="text updated">更新于:<time datetime="2025-02-16T13:38:50.846Z">2025-02-16</time></span></div></div></div>
<div class="bottom only-title">
<div class="text-area">
<h1 class="text title"><span>cJson数据格式问题</span></h1>
</div>
</div>
</div>
</div><article class="md-text content"><h2 id="问题描述"><a href="#问题描述" class="headerlink" title="问题描述"></a>问题描述</h2><p>Linux的换行符是<code>\n</code>,Windows的换行符是<code>\r\n</code>,在Linux系统下使用<a target="_blank" rel="noopener" href="https://github.com/DaveGamble/cJSON">cJson</a>库解析本地json文件没有问题,但如果把Windows的json文件拷贝到Linux下需要把<code>\r\n</code>给过滤掉,否则传入文件buffer就解析不出cJson对象!</p>
<h2 id="解决办法"><a href="#解决办法" class="headerlink" title="解决办法"></a>解决办法</h2><ol>
<li>一个简单的办法通过vim设置<code>set ff=unix</code>将文件改为Unix文件格式</li>
<li>通过c/c++实现trim或者trimmed接口过滤掉首尾两端空白符</li>
</ol>
<div class="article-footer fs14">
<section id="license">
<div class="header"><span>许可协议</span></div>
<div class="body"><p>本文采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">署名-非商业性使用-相同方式共享 4.0 国际</a> 许可协议,转载请注明出处。</p>
</div>
</section>
<section id="share">
<div class="header"><span>分享文章</span></div>
<div class="body">
<div class="link"><input class="copy-area" readonly="true" id="copy-link" value="https://blog.hywing.cn/cjson-file-format-problem.html" /></div>
<div class="social-wrap dis-select"><a class="social share-item wechat" onclick="util.toggle("qrcode-wechat")"><img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/social/b32ef3da1162a.svg" /></a><a class="social share-item weibo" target="_blank" rel="external nofollow noopener noreferrer" href="https://service.weibo.com/share/share.php?url=https://blog.hywing.cn/cjson-file-format-problem.html&title=cJson数据格式问题 - hywing's blog&summary=Bug解决"><img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/social/80c07e4dbb303.svg" /></a><a class="social share-item email" href="mailto:?subject=cJson数据格式问题 - hywing's blog&body=https://blog.hywing.cn/cjson-file-format-problem.html"><img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/social/a1b00e20f425d.svg" /></a><a class="social share-item link" onclick="util.copy("copy-link", "复制成功")"><img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/social/8411ed322ced6.svg" /></a></div>
<div class="qrcode" id="qrcode-wechat" style="opacity:0;height:0">
<img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://api.qrserver.com/v1/create-qr-code/?size=256x256&data=https://blog.hywing.cn/cjson-file-format-problem.html"/>
</div>
</div>
</section>
</div>
</article>
<div class="related-wrap" id="read-next"><section class="body"><div class="item" id="prev"><div class="note">较新文章</div><a href="/qnx-port-mongoose.html">QNX移植mongoose</a></div><div class="item" id="next"><div class="note">较早文章</div><a href="/professional-english.html">专业英语词汇</a></div></section></div>
<footer class="page-footer footnote"><hr><div class="sitemap"><div class="sitemap-group"><span class="fs15">博客</span><a href="/">近期</a><a href="/categories/">分类</a><a href="/tags/">标签</a><a href="/archives/">归档</a></div><div class="sitemap-group"><span class="fs15">项目</span><a href="/">开源库</a></div><div class="sitemap-group"><span class="fs15">社交</span><a href="/">友链</a><a href="/">留言板</a></div><div class="sitemap-group"><span class="fs15">更多</span><a href="/about">关于本站</a><a target="_blank" rel="noopener" href="https://github.com/hywing">GitHub</a></div></div><div class="text"><center>
<span>
© 2025
<a style="font-weight: bold; auto;" target="_blank" rel="noopener" href="https://github.com/hywing">hywing</a>
使用 <a style="font-weight: bold; auto;" target="_blank" rel="noopener" href="https://github.com/hywing/hexo-theme-stellar">Stellar</a>
创建
</span>
<br>
<!--不蒜子计数器-->
<script async="" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<!--添加一个访问量-->
<span>总访问 <span id="busuanzi_value_site_pv" style="font-weight: bold;">113701</span> 次 | 本页访问 <span id="busuanzi_value_page_pv" style="font-weight: bold;">326</span> 次</span>
</br>
<span id="runtime_span"></span>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var runtime_span = document.getElementById('runtime_span');
function show_runtime() {
// 调用定时器
setTimeout(show_runtime, 1000);
var seconds = 1000;
var minutes = seconds * 60;
var hours = minutes * 60;
var days = hours * 24;
var years = days * 365;
var today = new Date();
var todayYear = today.getFullYear();
var todayMonth = today.getMonth();
var todayDate = today.getDate();
var todayHour = today.getHours();
var todayMinute = today.getMinutes();
var todaySecond = today.getSeconds();
var t1 = Date.UTC(2025, 0, 5, 0, 0, 0); // UTC时间,月份从0开始
var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
var diff = t2 - t1;
var diffYears = Math.floor(diff / years);
var diffDays = Math.floor((diff / days) - diffYears * 365);
var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) / minutes);
var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours - diffMinutes * minutes) / seconds);
// 更新显示时间的span元素内容
runtime_span.innerHTML = "本网站已经稳定运行:" + diffYears + " 年 " + diffDays + " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒🦉";
}
show_runtime(); // 初次调用函数以启动定时器
});
</script>
</center>
</div></footer>
<div class="main-mask" onclick="sidebar.dismiss()"></div></div><aside class="l_right">
<div class="widgets">
<widget class="widget-wrapper toc" id="data-toc" collapse="false"><div class="widget-header dis-select"><span class="name">本文目录</span><a class="cap-action" onclick="sidebar.toggleTOC()" ><svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6h11m-11 6h11m-11 6h11M4 6h1v4m-1 0h2m0 8H4c0-1 2-2 2-3s-1-1.5-2-1"/></svg></a></div><div class="widget-body"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%97%AE%E9%A2%98%E6%8F%8F%E8%BF%B0"><span class="toc-text">问题描述</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95"><span class="toc-text">解决办法</span></a></li></ol></div><div class="widget-footer">
<a class="top" onclick="util.scrollTop()"><svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="1.5"><path d="M2 12c0-4.714 0-7.071 1.464-8.536C4.93 2 7.286 2 12 2c4.714 0 7.071 0 8.535 1.464C22 4.93 22 7.286 22 12c0 4.714 0 7.071-1.465 8.535C19.072 22 16.714 22 12 22s-7.071 0-8.536-1.465C2 19.072 2 16.714 2 12Z"/><path stroke-linecap="round" stroke-linejoin="round" d="m9 15.5l3-3l3 3m-6-4l3-3l3 3"/></g></svg><span>回到顶部</span></a></div></widget>
</div></aside><div class='float-panel blur'>
<button type='button' style='display:none' class='laptop-only rightbar-toggle mobile' onclick='sidebar.rightbar()'>
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6h11m-11 6h11m-11 6h11M4 6h1v4m-1 0h2m0 8H4c0-1 2-2 2-3s-1-1.5-2-1"/></svg>
</button>
<button type='button' style='display:none' class='mobile-only leftbar-toggle mobile' onclick='sidebar.leftbar()'>
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="1.5"><path d="M2 11c0-3.771 0-5.657 1.172-6.828C4.343 3 6.229 3 10 3h4c3.771 0 5.657 0 6.828 1.172C22 5.343 22 7.229 22 11v2c0 3.771 0 5.657-1.172 6.828C19.657 21 17.771 21 14 21h-4c-3.771 0-5.657 0-6.828-1.172C2 18.657 2 16.771 2 13z"/><path id="sep" stroke-linecap="round" d="M5.5 10h6m-5 4h4m4.5 7V3"/></g></svg>
</button>
</div>
</div><div class="scripts">
<script type="text/javascript">
const ctx = {
date_suffix: {
just: `刚刚`,
min: `分钟前`,
hour: `小时前`,
day: `天前`,
},
root : `/`,
};
// required plugins (only load if needs)
if (`local_search`) {
ctx.search = {};
ctx.search.service = `local_search`;
if (ctx.search.service == 'local_search') {
let service_obj = Object.assign({}, `{"field":"all","path":"/search.json","content":true,"sort":"-date"}`);
ctx.search[ctx.search.service] = service_obj;
}
}
const def = {
avatar: `https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/avatar/round/3442075.svg`,
cover: `https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/cover/76b86c0226ffd.svg`,
};
const deps = {
jquery: `https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js`,
marked: `https://cdn.jsdelivr.net/npm/marked@13.0.1/lib/marked.umd.min.js`
}
</script>
<script type="text/javascript">
const utils = {
// 懒加载 css https://github.com/filamentgroup/loadCSS
css: (href, before, media, attributes) => {
var doc = window.document;
var ss = doc.createElement("link");
var ref;
if (before) {
ref = before;
} else {
var refs = (doc.body || doc.getElementsByTagName("head")[0]).childNodes;
ref = refs[refs.length - 1];
}
var sheets = doc.styleSheets;
if (attributes) {
for (var attributeName in attributes) {
if (attributes.hasOwnProperty(attributeName)) {
ss.setAttribute(attributeName, attributes[attributeName]);
}
}
}
ss.rel = "stylesheet";
ss.href = href;
ss.media = "only x";
function ready(cb) {
if (doc.body) {
return cb();
}
setTimeout(function () {
ready(cb);
});
}
ready(function () {
ref.parentNode.insertBefore(ss, before ? ref : ref.nextSibling);
});
var onloadcssdefined = function (cb) {
var resolvedHref = ss.href;
var i = sheets.length;
while (i--) {
if (sheets[i].href === resolvedHref) {
return cb();
}
}
setTimeout(function () {
onloadcssdefined(cb);
});
};
function loadCB() {
if (ss.addEventListener) {
ss.removeEventListener("load", loadCB);
}
ss.media = media || "all";
}
if (ss.addEventListener) {
ss.addEventListener("load", loadCB);
}
ss.onloadcssdefined = onloadcssdefined;
onloadcssdefined(loadCB);
return ss;
},
js: (src, opt) => new Promise((resolve, reject) => {
var script = document.createElement('script');
if (src.startsWith('/')){
src = ctx.root + src.substring(1);
}
script.src = src;
if (opt) {
for (let key of Object.keys(opt)) {
script[key] = opt[key]
}
} else {
// 默认异步,如果需要同步,第二个参数传入 {} 即可
script.async = true
}
script.onerror = reject
script.onload = script.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
script.onload = script.onreadystatechange = null
resolve()
}
document.head.appendChild(script)
}),
jq: (fn) => {
if (typeof jQuery === 'undefined') {
utils.js(deps.jquery).then(fn)
} else {
fn()
}
},
onLoading: (el) => {
if (el) {
$(el).append('<div class="loading-wrap"><svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="2"><path stroke-dasharray="60" stroke-dashoffset="60" stroke-opacity=".3" d="M12 3C16.9706 3 21 7.02944 21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3Z"><animate fill="freeze" attributeName="stroke-dashoffset" dur="1.3s" values="60;0"/></path><path stroke-dasharray="15" stroke-dashoffset="15" d="M12 3C16.9706 3 21 7.02944 21 12"><animate fill="freeze" attributeName="stroke-dashoffset" dur="0.3s" values="15;0"/><animateTransform attributeName="transform" dur="1.5s" repeatCount="indefinite" type="rotate" values="0 12 12;360 12 12"/></path></g></svg></div>');
}
},
onLoadSuccess: (el) => {
if (el) {
$(el).find('.loading-wrap').remove();
}
},
onLoadFailure: (el) => {
if (el) {
$(el).find('.loading-wrap svg').remove();
$(el).find('.loading-wrap').append('<svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path stroke-dasharray="60" stroke-dashoffset="60" d="M12 3L21 20H3L12 3Z"><animate fill="freeze" attributeName="stroke-dashoffset" dur="0.5s" values="60;0"/></path><path stroke-dasharray="6" stroke-dashoffset="6" d="M12 10V14"><animate fill="freeze" attributeName="stroke-dashoffset" begin="0.6s" dur="0.2s" values="6;0"/></path></g><circle cx="12" cy="17" r="1" fill="currentColor" fill-opacity="0"><animate fill="freeze" attributeName="fill-opacity" begin="0.8s" dur="0.4s" values="0;1"/></circle></svg>');
$(el).find('.loading-wrap').addClass('error');
}
},
request: (el, url, callback, onFailure) => {
let retryTimes = 3;
utils.onLoading(el);
function req() {
return new Promise((resolve, reject) => {
let status = 0; // 0 等待 1 完成 2 超时
let timer = setTimeout(() => {
if (status === 0) {
status = 2;
timer = null;
reject('请求超时');
if (retryTimes == 0) {
onFailure();
}
}
}, 5000);
fetch(url).then(function(response) {
if (status !== 2) {
clearTimeout(timer);
resolve(response);
timer = null;
status = 1;
}
if (response.ok) {
return response.json();
}
throw new Error('Network response was not ok.');
}).then(function(data) {
retryTimes = 0;
utils.onLoadSuccess(el);
callback(data);
}).catch(function(error) {
if (retryTimes > 0) {
retryTimes -= 1;
setTimeout(() => {
req();
}, 5000);
} else {
utils.onLoadFailure(el);
onFailure();
}
});
});
}
req();
},
};
</script>
<script>
const sidebar = {
leftbar: () => {
if (l_body) {
l_body.toggleAttribute('leftbar');
l_body.removeAttribute('rightbar');
}
},
rightbar: () => {
if (l_body) {
l_body.toggleAttribute('rightbar');
l_body.removeAttribute('leftbar');
}
},
dismiss: () => {
if (l_body) {
l_body.removeAttribute('leftbar');
l_body.removeAttribute('rightbar');
}
},
toggleTOC: () => {
document.querySelector('#data-toc').classList.toggle('collapse');
}
}
</script>
<script type="text/javascript">
(() => {
const tagSwitchers = document.querySelectorAll('.tag-subtree.parent-tag > a > .tag-switcher-wrapper')
for (const tagSwitcher of tagSwitchers) {
tagSwitcher.addEventListener('click', (e) => {
const parent = e.target.closest('.tag-subtree.parent-tag')
parent.classList.toggle('expanded')
e.preventDefault()
})
}
// Get active tag from query string, then activate it.
const urlParams = new URLSearchParams(window.location.search)
const activeTag = urlParams.get('tag')
if (activeTag) {
let tag = document.querySelector(`.tag-subtree[data-tag="${activeTag}"]`)
if (tag) {
tag.querySelector('a').classList.add('active')
while (tag) {
tag.classList.add('expanded')
tag = tag.parentElement.closest('.tag-subtree.parent-tag')
}
}
}
})()
</script>
<!-- required -->
<script src="/js/main.js?v=1.29.1" defer></script>
<script type="text/javascript">
const applyTheme = (theme) => {
if (theme === 'auto') {
document.documentElement.removeAttribute('data-theme')
} else {
document.documentElement.setAttribute('data-theme', theme)
}
applyThemeToGiscus(theme)
}
const applyThemeToGiscus = (theme) => {
theme = theme === 'auto' ? 'preferred_color_scheme' : theme
const cmt = document.getElementById('giscus')
if (cmt) {
// This works before giscus load.
cmt.setAttribute('data-theme', theme)
}
const iframe = document.querySelector('#comments > section.giscus > iframe')
if (iframe) {
// This works after giscus loaded.
const src = iframe.src
const newSrc = src.replace(/theme=[\w]+/, `theme=${theme}`)
iframe.src = newSrc
}
}
const switchTheme = () => {
// light -> dark -> auto -> light -> ...
const currentTheme = document.documentElement.getAttribute('data-theme')
let newTheme;
switch (currentTheme) {
case 'light':
newTheme = 'dark'
break
case 'dark':
newTheme = 'auto'
break
default:
newTheme = 'light'
}
applyTheme(newTheme)
window.localStorage.setItem('Stellar.theme', newTheme)
const messages = {
light: `切换到浅色模式`,
dark: `切换到深色模式`,
auto: `切换到跟随系统配色`,
}
hud?.toast?.(messages[newTheme])
}
(() => {
// Apply user's preferred theme, if any.
const theme = window.localStorage.getItem('Stellar.theme')
if (theme !== null) {
applyTheme(theme)
}
})()
</script>
<!-- optional -->
<script defer>
window.addEventListener('DOMContentLoaded', (event) => {
ctx.services = Object.assign({}, JSON.parse(`{"mdrender":{"js":"/js/services/mdrender.js"},"siteinfo":{"js":"/js/services/siteinfo.js","api":null},"ghinfo":{"js":"/js/services/ghinfo.js"},"sites":{"js":"/js/services/sites.js"},"friends":{"js":"/js/services/friends.js"},"timeline":{"js":"/js/services/timeline.js"},"fcircle":{"js":"/js/services/fcircle.js"},"weibo":{"js":"/js/services/weibo.js"},"memos":{"js":"/js/services/memos.js"}}`));
for (let id of Object.keys(ctx.services)) {
const js = ctx.services[id].js;
if (id == 'siteinfo') {
ctx.cardlinks = document.querySelectorAll('a.link-card[cardlink]');
if (ctx.cardlinks?.length > 0) {
utils.js(js, { defer: true }).then(function () {
setCardLink(ctx.cardlinks);
});
}
} else {
const els = document.getElementsByClassName(`ds-${id}`);
if (els?.length > 0) {
utils.jq(() => {
if (id == 'timeline' || 'memos' || 'marked') {
utils.js(deps.marked).then(function () {
utils.js(js, { defer: true });
});
} else {
utils.js(js, { defer: true });
}
});
}
}
}
});
</script>
<script>
window.addEventListener('DOMContentLoaded', (event) => {
ctx.search = {
path: `/search.json`,
}
utils.js('/js/search/local-search.js', { defer: true });
});
</script><script>
window.FPConfig = {
delay: 0,
ignoreKeywords: [],
maxRPS: 5,
hoverDelay: 25
};
</script>
<script defer src="https://cdn.jsdelivr.net/npm/flying-pages@2/flying-pages.min.js"></script><script defer src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@19.1.3/dist/lazyload.min.js"></script>
<script>
// https://www.npmjs.com/package/vanilla-lazyload
// Set the options globally
// to make LazyLoad self-initialize
window.lazyLoadOptions = {
elements_selector: ".lazy",
};
// Listen to the initialization event
// and get the instance of LazyLoad
window.addEventListener(
"LazyLoad::Initialized",
function (event) {
window.lazyLoadInstance = event.detail.instance;
},
false
);
document.addEventListener('DOMContentLoaded', function () {
window.lazyLoadInstance?.update();
});
</script><script>
ctx.fancybox = {
selector: `.timenode p>img`,
css: `https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0/dist/fancybox/fancybox.css`,
js: `https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0/dist/fancybox/fancybox.umd.js`
};
var selector = '[data-fancybox]:not(.error)';
if (ctx.fancybox.selector) {
selector += `, ${ctx.fancybox.selector}`
}
var needFancybox = document.querySelectorAll(selector).length !== 0;
if (!needFancybox) {
const els = document.getElementsByClassName('ds-memos');
if (els != undefined && els.length > 0) {
needFancybox = true;
}
}
if (needFancybox) {
utils.css(ctx.fancybox.css);
utils.js(ctx.fancybox.js, { defer: true }).then(function () {
Fancybox.bind(selector, {
hideScrollbar: false,
Thumbs: {
autoStart: false,
},
caption: (fancybox, slide) => {
return slide.triggerEl.alt || slide.triggerEl.dataset.caption || null
}
});
})
}
</script>
<script>
window.addEventListener('DOMContentLoaded', (event) => {
const swiper_api = document.getElementById('swiper-api');
if (swiper_api != undefined) {
utils.css(`https://unpkg.com/swiper@10.3.1/swiper-bundle.min.css`);
utils.js(`https://unpkg.com/swiper@10.3.1/swiper-bundle.min.js`, { defer: true }).then(function () {
const effect = swiper_api.getAttribute('effect') || '';
var swiper = new Swiper('.swiper#swiper-api', {
slidesPerView: 'auto',
spaceBetween: 8,
centeredSlides: true,
effect: effect,
rewind: true,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
});
})
}
});
</script>
<script>
document.addEventListener('DOMContentLoaded', function () {
window.codeElements = document.querySelectorAll('.code');
if (window.codeElements.length > 0) {
ctx.copycode = {
default_text: `Copy`,
success_text: `Copied`,
toast: `复制成功`,
};
utils.js('/js/plugins/copycode.js');
}
});
</script>
<!-- inject -->
</div></body></html>