JsonParserByLeo/Test/Test.mq5
93 lines
3 KiB
MQL5
Nique_372
2026-06-03 07:50:45 -05:00
//+------------------------------------------------------------------+
//| Test.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
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
Nique_372
2026-10-08 19:54:46 -05:00
#include "..\\Src\\JsonNode\\JsonNode.mqh"
Nique_372
2026-07-10 13:17:36 -05:00
Nique_372
2026-06-03 07:50:45 -05:00
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
Nique_372
2026-07-10 13:17:36 -05:00
Nique_372
2026-06-03 07:50:45 -05:00
//---
Nique_372
2026-08-03 10:47:54 -05:00
Nique_372
2026-08-03 09:31:58 -05:00
string json = "{\"ae\":[[10,10],[20,20],[]],\"comida\":\"\\ud83d\\ude00\",\"trapo\":10.05,\"a\":true,\"invalid\":\"<a href=\\\"https://twitter.com/shiawaseomamori\\\" rel=\\\"nofollow\\\">幸せの☆お守り</a>\",\"precios\":[10,20,30,40,50],\"va\":1"
Nique_372
2026-07-15 16:03:07 -05:00
",\"interpolado\":\"${{valor}}\"}";
Nique_372
2026-08-03 10:47:54 -05:00
Nique_372
2026-06-20 13:57:50 -05:00
//Print(json);
Nique_372
2026-06-03 07:50:45 -05:00
//---
TSN::CJsonParser parser;
parser.Assing(json);
Nique_372
2026-07-19 07:41:52 -05:00
parser.CorrectPadding();
Nique_372
2026-08-27 13:40:38 -05:00
Print(parser.Parse());
Nique_372
2026-08-03 15:01:11 -05:00
parser.ErrorInfo();
Nique_372
2026-06-20 18:08:19 -05:00
parser.PrintCintaTypes(0, WHOLE_ARRAY);
Nique_372
2026-06-03 07:50:45 -05:00
//---
TSN::CJsonNode root = parser.GetRoot();
Nique_372
2026-06-20 18:08:19 -05:00
Nique_372
2026-06-21 20:08:59 -05:00
//---
Print("Claves: ");
string keys[];
root.GetKeys(keys);
ArrayPrint(keys, _Digits, " | ");
Nique_372
2026-06-24 17:20:42 -05:00
//--- Calentar para JIT (3 iter)
for(int i = 0; i < 7; i++)
{
root["trapo"].ToDouble(0.00);
}
Print("Root is JIT: ", root.ObjectIsJit());
Nique_372
2026-06-21 20:08:59 -05:00
//---
Nique_372
2026-10-08 19:54:46 -05:00
//const string tres = root.AtObjKey(3);
//Print("Tercera key: ", tres, " index: ", root.KeyToPosition(tres));
Nique_372
2026-06-21 20:08:59 -05:00
Nique_372
2026-06-20 13:57:50 -05:00
//---
Nique_372
2026-06-20 18:08:19 -05:00
Print("Trapo val: ", root["trapo"].ToDouble(0.00));
Nique_372
2026-07-26 16:46:05 -05:00
Nique_372
2026-07-17 10:08:58 -05:00
//---
Nique_372
2026-06-21 20:08:59 -05:00
TSN::CJsonNode fa = root["ae"].At(0);
Print("Valor anidado: ", fa.At(0).ToInt(0)); // 10
//---
Nique_372
2026-10-24 12:45:01 -05:00
string precios[];
Nique_372
2026-06-21 20:08:59 -05:00
Print("Array precios: ");
root["precios"].ToArray(precios);
ArrayPrint(precios, _Digits, " | ");
Nique_372
2026-10-24 12:45:01 -05:00
PrintFormat("Precio[0] = '%s'", root["precios"].At(0).ToString());
Nique_372
2026-06-20 13:57:50 -05:00
Nique_372
2026-06-20 18:08:19 -05:00
//---
Print("Root key el 0: ", root.AtObjKey(0));
Print("Root size: ", root.Size());
Print("Root is valid: ", root.IsValid());
Print("Root emoji: ", root["comida"].ToString());
Nique_372
2026-06-23 08:02:37 -05:00
Print("Root emoji no escape: ", root["comida"].ToStringNoEscape());
Nique_372
2026-06-20 18:08:19 -05:00
Print("Root invalid: ", root["invalid"].ToString());
Nique_372
2026-06-23 08:02:37 -05:00
Print("Has key comida: ", root.HasKey("comida"));
Print("First value type obj: ", EnumToString(root.AtObj(0).GetType()));
Nique_372
2026-06-30 08:24:44 -05:00
Print("Va value:", root["va"].ToInt(0));
Nique_372
2026-06-21 20:08:59 -05:00
Nique_372
2026-06-20 18:08:19 -05:00
//---
Nique_372
2026-07-26 16:46:05 -05:00
Print("Iteracion ----");
CJsonIteratorObj it = root.BeginObj();
Nique_372
2026-06-20 18:08:19 -05:00
while(it.IsValid())
{
Nique_372
2026-10-08 21:46:49 -05:00
Print("Element of root: ", parser.GetRawAsStr<JPBL_STR_KEY>(it.KeyIndex()));
Nique_372
2026-06-20 18:08:19 -05:00
it.Next();
}
Nique_372
2026-06-03 07:50:45 -05:00
}
//+------------------------------------------------------------------+