Last active
October 21, 2016 13:15
-
-
Save bithavoc/8686903 to your computer and use it in GitHub Desktop.
Demo of Parsing objects using instances of JSONValue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * http://johan.heapsource.com | |
| */ | |
| import std.stdio; | |
| import std.json; | |
| JSONValue doc; | |
| void main() { | |
| parseMyDoc(); | |
| printMyDoc(); | |
| } | |
| void parseMyDoc() { | |
| JSONValue v = parseJSON(q{ | |
| {"a":2, "b":{"c":20}} | |
| }); | |
| doc = v; | |
| } | |
| void printMyDoc() { | |
| string str = toJSON(&doc, true); | |
| writeln(str); | |
| } | |
| // (Output) | |
| /* | |
| { | |
| "a": 2, | |
| "b": { | |
| "c": 20 | |
| } | |
| } | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * http://johan.heapsource.com | |
| */ | |
| import std.stdio; | |
| import std.json; | |
| JSONValue * doc; | |
| void main() { | |
| parseMyDoc(); | |
| printMyDoc(); | |
| } | |
| void parseMyDoc() { | |
| JSONValue v = parseJSON(q{ | |
| {"a":2, "b":{"c":20}} | |
| }); | |
| doc = &v; | |
| } | |
| void printMyDoc() { | |
| string str = toJSON(doc, true); | |
| writeln(str); | |
| } | |
| // (Undefined behavior or Segmentation Fault) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * http://johan.heapsource.com | |
| */ | |
| import std.stdio; | |
| import std.json; | |
| void main() { | |
| JSONValue * v = new JSONValue; | |
| *v = parseJSON(q{ | |
| {"a":2, "b":{"c":20}} | |
| }); | |
| string str = v.toJSON(true); | |
| writeln(str); | |
| } | |
| // (Output) | |
| /* | |
| { | |
| "a": 2, | |
| "b": { | |
| "c": 20 | |
| } | |
| } | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * http://johan.heapsource.com | |
| */ | |
| import std.stdio; | |
| import std.json; | |
| void main() { | |
| JSONValue v = parseJSON(q{ | |
| {"a":2, "b":{"c":20}} | |
| }); | |
| string str = toJSON(&v, true); | |
| writeln(str); | |
| } | |
| // (Output) | |
| /* | |
| { | |
| "a": 2, | |
| "b": { | |
| "c": 20 | |
| } | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment