Created
November 8, 2017 20:06
-
-
Save Craigson/96231f343d592e79327bb46b373bee01 to your computer and use it in GitHub Desktop.
Basic example of working with a ci::JsonTree
This file contains 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
/* | |
{ | |
"results" : [ | |
{ | |
"index": 0, | |
"description" : "cats are here", | |
"head" : { | |
"posterior" : 0.0, | |
"anterior" : 0.0 | |
}, | |
"spine_base": { | |
"posterior" : 0.0, | |
"anterior" : 0.0 | |
}, | |
"spine_neck":{ | |
"posterior" : 0.0, | |
"anterior" : 0.0 | |
} | |
}, | |
... | |
] | |
} | |
*/ | |
JsonTree results = JsonTree::makeArray("results"); | |
for (int i = 0 ; i < 5; i++) | |
{ | |
JsonTree temp = JsonTree::makeObject(); | |
temp.addChild(JsonTree("index", i)); | |
temp.addChild(JsonTree("description", "cats are here")); | |
JsonTree head = JsonTree::makeObject("head"); | |
head.addChild(JsonTree("posterior", 0.03)); | |
head.addChild(JsonTree("anterior", 0.15)); | |
temp.addChild(head); | |
JsonTree spine_neck = JsonTree::makeObject("spine_neck"); | |
spine_neck.addChild(JsonTree("posterior", 0.56)); | |
spine_neck.addChild(JsonTree("anterior", -0.33)); | |
temp.addChild(spine_neck); | |
JsonTree spine_base = JsonTree::makeObject("spine_base"); | |
spine_base.addChild(JsonTree("posterior", 1.6)); | |
spine_base.addChild(JsonTree("anterior", 0.89)); | |
temp.addChild(spine_base); | |
results.pushBack(temp); | |
} | |
mTree.addChild(results); | |
fs::path saveLoc (ci::getHomeDirectory().string() + "/temp/readings.json"); | |
mTree.write(saveLoc); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment