reference: JSON reference example

git-svn-id: svn://ultimatepp.org/upp/trunk@4126 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2011-11-04 18:19:14 +00:00
parent 258d544fac
commit 94d5403673
4 changed files with 126 additions and 0 deletions

33
reference/JSON/main.cpp Normal file
View file

@ -0,0 +1,33 @@
#include "JSON.h"
CONSOLE_APP_MAIN
{
Value js = ParseJSON(LoadFile(GetDataFile("test.json")));
DUMP(js);
DUMP(js["age"]);
Value phone_number = js["phoneNumber"];
DUMP(phone_number);
DUMP(phone_number.GetCount());
for(int i = 0; i < phone_number.GetCount(); i++) {
DUMP(phone_number[i]["type"]);
DUMP(phone_number[i]["number"]);
}
DUMP(AsJSON(js, true));
DUMP(AsJSON(js));
LOG("- Partial parsing");
ValueArray va;
va << js << js << js;
String s = AsJSON(va);
DUMP(s);
CParser p2(s);
p2.PassChar('[');
if(!p2.Char(']')) {
do {
DUMP(ParseJSON(p2)["firstName"]);
}
while(p2.Char(','));
p2.PassChar(']');
}
}