File: test.html

package info (click to toggle)
json-js 0~20180723-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 152 kB
  • sloc: makefile: 16; sh: 6
file content (36 lines) | stat: -rw-r--r-- 804 bytes parent folder | download
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
<html><body><script src="cycle.js"></script>
<pre><p id=output></p>
<script>
function out(s) {
    document.getElementById('output').innerHTML += s + '<br>';
}

function doTest() {
    var i, o, s, jsonObj;
    try {
        o = {
            number: 98.6,
            string: 'Why is it called string?'
        };
        o.object = o;
        o.array = [o];
        out(JSON.stringify(JSON.decycle(
            [o, o],
            function (value) {
                if (typeof value === 'string') {
                    return 'because';
                } else {
                    return value;
                }
            }
        )));

    } catch (e) {
        debugger;
        out("    name: " + e.name);
        out(" message: " + e.message);
    }
}

doTest();
</script></pre></body></html>