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
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-10-08 19:54:46 -05:00 | | | #include "..\\Src\\JsonNode\\JsonNode.mqh"
|
2026-07-10 13:17:36 -05:00 | | |
|
2026-06-03 07:50:45 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Script program start function |
|
| | | //+------------------------------------------------------------------+
|
| | | void OnStart()
|
| | | {
|
2026-07-10 13:17:36 -05:00 | | |
|
2026-06-03 07:50:45 -05:00 | | | //---
|
2026-08-03 10:47:54 -05:00 | | |
|
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"
|
2026-07-15 16:03:07 -05:00 | | | ",\"interpolado\":\"${{valor}}\"}";
|
2026-08-03 10:47:54 -05:00 | | |
|
| | |
|
| | |
|
2026-06-20 13:57:50 -05:00 | | | //Print(json);
|
2026-06-03 07:50:45 -05:00 | | | //---
|
| | | TSN::CJsonParser parser;
|
2026-06-04 11:36:42 -05:00 | | | parser.Assing(json);
|
2026-07-19 07:41:52 -05:00 | | | parser.CorrectPadding();
|
2026-08-27 13:40:38 -05:00 | | | Print(parser.Parse());
|
2026-08-03 15:01:11 -05:00 | | | parser.ErrorInfo();
|
2026-06-20 18:08:19 -05:00 | | | parser.PrintCintaTypes(0, WHOLE_ARRAY);
|
2026-06-03 07:50:45 -05:00 | | |
|
| | | //---
|
| | | TSN::CJsonNode root = parser.GetRoot();
|
2026-06-20 18:08:19 -05:00 | | |
|
2026-06-21 20:08:59 -05:00 | | | //---
|
| | | Print("Claves: ");
|
| | | string keys[];
|
| | | root.GetKeys(keys);
|
| | | ArrayPrint(keys, _Digits, " | ");
|
| | |
|
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());
|
| | |
|
2026-06-21 20:08:59 -05:00 | | | //---
|
2026-10-08 19:54:46 -05:00 | | | //const string tres = root.AtObjKey(3);
|
| | | //Print("Tercera key: ", tres, " index: ", root.KeyToPosition(tres));
|
2026-06-21 20:08:59 -05:00 | | |
|
2026-06-20 13:57:50 -05:00 | | | //---
|
2026-06-20 18:08:19 -05:00 | | | Print("Trapo val: ", root["trapo"].ToDouble(0.00));
|
2026-07-26 16:46:05 -05:00 | | |
|
2026-07-17 10:08:58 -05:00 | | | //---
|
2026-06-21 20:08:59 -05:00 | | | TSN::CJsonNode fa = root["ae"].At(0);
|
| | | Print("Valor anidado: ", fa.At(0).ToInt(0)); // 10
|
| | |
|
| | | //---
|
2026-10-24 12:45:01 -05:00 | | | string precios[];
|
2026-06-21 20:08:59 -05:00 | | | Print("Array precios: ");
|
| | | root["precios"].ToArray(precios);
|
| | | ArrayPrint(precios, _Digits, " | ");
|
2026-10-24 12:45:01 -05:00 | | | PrintFormat("Precio[0] = '%s'", root["precios"].At(0).ToString());
|
2026-06-20 13:57:50 -05:00 | | |
|
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());
|
2026-06-23 08:02:37 -05:00 | | | Print("Root emoji no escape: ", root["comida"].ToStringNoEscape());
|
2026-06-20 18:08:19 -05:00 | | | Print("Root invalid: ", root["invalid"].ToString());
|
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()));
|
2026-06-30 08:24:44 -05:00 | | | Print("Va value:", root["va"].ToInt(0));
|
2026-06-21 20:08:59 -05:00 | | |
|
2026-06-20 18:08:19 -05:00 | | | //---
|
2026-07-26 16:46:05 -05:00 | | | Print("Iteracion ----");
|
| | | CJsonIteratorObj it = root.BeginObj();
|
2026-06-20 18:08:19 -05:00 | | | while(it.IsValid())
|
| | | {
|
2026-10-08 21:46:49 -05:00 | | | Print("Element of root: ", parser.GetRawAsStr<JPBL_STR_KEY>(it.KeyIndex()));
|
2026-06-20 18:08:19 -05:00 | | | it.Next();
|
| | | }
|
2026-06-03 07:50:45 -05:00 | | | }
|
| | | //+------------------------------------------------------------------+
|