65 lines
2.4 KiB
C++
65 lines
2.4 KiB
C++
#include "pip.h"
|
||
#include "piiostream.h"
|
||
#include "pibytearray.h"
|
||
#include "pimathbase.h"
|
||
#include "pijson.h"
|
||
|
||
using namespace PICoutManipulators;
|
||
|
||
typedef PIMap<PIString, PIVariant> PIVariantMap;
|
||
typedef PIVector<PIVariant> PIVariantVector;
|
||
|
||
REGISTER_VARIANT(PIVariantMap);
|
||
REGISTER_VARIANT(PIVariantVector);
|
||
|
||
const char J[] =
|
||
"[ \n"
|
||
"{ \n"
|
||
" \"idFligth\":\"456123\", \n"
|
||
" \"FligthPath\": \"d:/orders/nicirt/BSK-52(BBR)/219031.001/EBN-NM-BBR.IMG\",\n"
|
||
" \"FligthDataPath\": \"\", \n"
|
||
" \"Passport\": \n"
|
||
" { \n"
|
||
" \"id\": \"\", \n"
|
||
" \"TypePlane\": \"\", \n"
|
||
" \"FA_PLANEBORT\": \"Ka52-10\" \n"
|
||
" } \n"
|
||
" }, [1.1,2,3,4,{\"a\":null},{\"bool\":true,\"bool2\":false}] \n"
|
||
"] \n"
|
||
;
|
||
|
||
|
||
int main(int argc, char * argv[]) {
|
||
PIString s;
|
||
s = PIString::fromUTF8(J).trim();
|
||
s = PIString::fromUTF8("{\"st\\u0426r\":\"\\\\ \\\" \\u0425\\u0430\\n\"}");
|
||
//s = PIString::fromUTF8("{\"str\":\"Ха\"}");
|
||
PIJSON json = PIJSON::fromJSON(s);
|
||
//piCout << json;
|
||
//piCout << json.toJSON();
|
||
//json.resize(3);
|
||
//json["0"].setValue(123);
|
||
//json["1"].setValue("sec");
|
||
//json["2"]["f"].setValue(true);
|
||
//json["2"]["s"].setValue(-1);*/
|
||
//json[0]["Passport"]["id"] = 0xFF;
|
||
//piCout << json;
|
||
json = PIJSON();
|
||
json[0] = 123;
|
||
json[1] = PIString::fromUTF8("string русский хаха !");
|
||
json[2]["b"] = true;
|
||
json[2]["i"] = -1;
|
||
auto & arr(json[3]);
|
||
arr[0] = 10;
|
||
arr[1] = 11.2E-1;
|
||
arr[2] = "!!!";
|
||
json[5] = json[2];
|
||
json[7] = false;
|
||
//piCout << json;
|
||
piCout << json;
|
||
piCout << json.toJSON(PIJSON::Tree);
|
||
piCout << json.toJSON(PIJSON::Compact);
|
||
//piCout << json["str__"].toString().toUTF8();
|
||
return 0;
|
||
}
|