Files
pip/main.cpp
2022-09-26 17:49:58 +03:00

63 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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::newObject();
json["num"] = 123;
json["str__"] = PIString::fromUTF8("string русский ℃ 😆 ");
json["obj"]["b"] = true;
json["obj"]["i"] = -1;
auto & arr(json["obj"]["arr"]);
arr.resize(3);
arr[0] = 10;
arr[1] = 11.2E-1;
arr[2] = "!!!";
json["obj2"] = json["obj"];
//piCout << json;
piCout << json.toJSON();
piCout << json["str__"].toString().toUTF8();
return 0;
}