Examples
Create a JSON object
PHP Code:
YYJSONObject hJSONObject = new YYJSONObject();
hJSONObject.SetInt("int", 1);
hJSONObject.SetInt64("int64", "9223372036854775800");
hJSONObject.SetFloat("float", 2.0);
hJSONObject.SetBool("bool", true);
hJSONObject.SetString("str", "Hello World");
hJSONObject.SetNull("null");
delete hJSONObject;
/*
{
"int": 1,
"int64": 9223372036854775800,
"float": 2.0,
"bool": true,
"str": "Hello World",
"null": null
}
*/
Create a JSON array
PHP Code:
YYJSONArray hJSONArray = new YYJSONArray();
hJSONArray.PushInt(1);
hJSONArray.PushInt64("9223372036854775800");
hJSONArray.PushFloat(2.0);
hJSONArray.PushBool(true);
hJSONArray.PushString("Hello World");
hJSONArray.PushNull();
delete hJSONArray;
/*
[
1,
9223372036854775800,
2.0,
true,
"Hello World",
null
]
*/
JSON POINTER: Create a JSON object
PHP Code:
YYJSONObject hJSONObject = new YYJSONObject();
hJSONObject.PtrSetInt("/a/b/c", 1);
delete hJSONObject;
/*
{
"a": {
"b": {
"c": 1
}
}
}
*/
JSON POINTER: Query data
PHP Code:
/*
{
"bool": true,
"float": 1.234,
"int": 1234,
"int64": 9223372036854775807,
"null": null,
"string": "hello world",
"arr": [
false,
1.2344,
1234,
9223372036854775807,
null,
"Hello World"
]
}
*/
hPtrTest.PtrGetInt("/int"); // 1234
hPtrTest.PtrGetFloat("/arr/1"); // 1.2344
delete hPtrTest;
Iteration Objects
PHP Code:
char key[64];
YYJSON val;
for (int i = 0; i < hPtrTest.Size; i++)
{
hPtrTest.GetName(i, key, sizeof(key));
PrintToServer("key: %s", key);
val = hPtrTest.GetValueAt(i);
// do something
delete val;
}
Iteration Arrays
PHP Code:
YYJSONArray arr = hPtrTest.PtrGet("/arr");
YYJSON val;
for (int i = 0; i < arr.Length; i++)
{
val = arr.Get(i);
// do something
delete val;
}
delete arr;