reference: Jsonize

git-svn-id: svn://ultimatepp.org/upp/trunk@4816 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-04-19 07:37:30 +00:00
commit 7ef69f8672
5 changed files with 91 additions and 18 deletions

View file

@ -0,0 +1,59 @@
#include <Core/Core.h>
using namespace Upp;
struct Data {
Size sz;
String text;
Vector<Size> vector;
VectorMap<String, int> score;
VectorMap<String, String> map;
ArrayMap<int, Size> sizemap;
double number;
bool option;
void Jsonize(JsonIO& json);
};
void Data::Jsonize(JsonIO& json)
{
json
("Dimension", sz)
("text", text)
("vector", vector)
("Scores", score)
("map", map)
("sizemap", sizemap)
("number", number)
("option", option)
;
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
Data x;
x.sz.cx = 10;
x.sz.cy = 20;
x.text = "Some text";
x.vector.Add(Size(1, 2));
x.vector.Add(Size(3, 4));
x.score.Add("peter", 100);
x.score.Add("john", 10);
x.score.Add("frank", 20);
x.map.Add("keytext", "valuetext");
x.map.Add("key1text", "value1text");
x.sizemap.Add(1, Size(2, 3));
x.sizemap.Add(10, Size(20, 30));
x.number = -1.235e-30;
x.option = true;
String json = StoreAsJson(x, true);
LOG(json);
LOG("=====================");
Data y;
DUMP(LoadFromJson(y, json));
LOG(StoreAsJson(y));
}

View file

@ -0,0 +1,9 @@
uses
Core;
file
Jsonize.cpp;
mainconfig
"" = "SSE2";

4
reference/Jsonize/init Normal file
View file

@ -0,0 +1,4 @@
#ifndef _Jsonize_icpp_init_stub
#define _Jsonize_icpp_init_stub
#include "Core/init"
#endif