JsonParserByLeo/Test/Dom.mq5
Nique_372 f64e96a1b3
2026-07-20 09:30:41 -05:00

80 Zeilen
Kein EOL
2,5 KiB
MQL5

//+------------------------------------------------------------------+
//| Dom.mq5 |
//| Copyright 2026, Niquel Mendoza. |
//| https://www.mql5.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza."
#property link "https://www.mql5.com/"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "..\\Src\\JsonNode.mqh"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
string json = "{\"ae\":[[10,10],[20,20]],\"comida\":\"\\ud83d\\ude00\",\"trapo\":10.05,\"a\":true,\"invalid\":\"\\xFF\",\"precios\":[10,20,30,40,50],\"va\":1"
",\"interpolado\":\"${{valor}}\"}";
//Print(json);
//---
TSN::CJsonParser parser;
parser.Assing(json);
parser.CorrectPadding();
parser.Parse();
parser.PrintCintaTypes(0, WHOLE_ARRAY);
//---
TSN::CDomNodeBase* root;
TSN::CDomNodeManager manager;
TSN::CJsonDomSerializer serializer;
parser.GetRoot().ToDom(root, &manager);
//---
string kes[];
root.GetKeys(kes);
ArrayPrint(kes);
//---
Print(root.Size());
Print(root["trapo"].ToDouble(0.0));
Print(root["ae"].At(1).At(1).ToInt(0));
Print(root["comida"].ToString());
// Agregar y cambiar tipo
root["sumando"] = 20.0;
Print(root.Size());
Print(root["sumando"].ToDouble(0.0));
root["sumando"] = true;
Print(root["sumando"].ToBool(false));
//--- Estadisticas
Print("Numero de arrays creados: ", manager.m_node_size);
Print("Numero de objetos creados: ", manager.m_objs_size);
Print("Numero de strgins creados: ", manager.m_string_stack_size);
//--- Otro json
TSN::CDomNodeManager manager2;
TSN::CDomNodeBase* ptr = new TSN::CDomNodeBase(&manager2); // vacio
ptr.NewObj(128);
ptr["valores"] = 20.0;
//---
root.Set("nueva_key", ptr); // No copia profunda si no PUNTERO..
ptr["coma"] = true;
//---
Print(serializer.Serialize(root));
Print(CharArrayToString(serializer.m_buf, 0, serializer.m_buf_s));
//---
delete root;
delete ptr;
}
//+------------------------------------------------------------------+