EA31337 / EA31337-classes

📦📈 EA31337 framework (MQL library for writing trading Expert Advisors, indicators and scripts)
https://ea31337.github.io/EA31337-classes
GNU General Public License v3.0
188 stars 99 forks source link

Dict: Add ToString() and ToJSON() #88

Closed kenorb closed 4 years ago

kenorb commented 4 years ago

Expand Dict class to add ToJSON() method (similar to ToString()). The method should return all elements in the plain JSON format.

E.g.

  // ToJSON()
  Dict<string, int> dict1;
  dict1.Set("a", 1);
  dict1.Set("bb", 2);
  Print(dict1.ToJSON()); // {"a": 1, "bb": 2}
  // ToString()
  Dict<string, int> dict2;
  dict2.Set("a", 1);
  dict2.Set("bb", 2);
  Print(dict2.ToString(";")); // a=1;bb=2
  Print(dict2.ToString("\n")); // a=1\nbb=2

We can either implement as the self-contained method, or create a JSON class as a wrapper (as ToJSON() could be also re-used in other classes).

Not sure if we can have multiple hierarchy such as Dict<string, Dict> dict; (depending on the complexity), so for now we can only support the flat list.

Tasks:

kenorb commented 4 years ago

Fixed in #102