Libraries: JSON Serialization and Deserialization (native MQL) - page 3

 

Well, it turns out that it's just an array of objects.

the general appearance of "Array": [ {..}, {..}, ]

I mean, wrap this list in curly braces.

"List": [ {"symbol": "USDJPY", "type": "Buy" },  { "symbol": "EURUSD", "type": "Sell" } ]
 

I limited it with square brackets. But only the first object is read:

[ {
     "symbol": "USDJPY",
     "type": "Buy",
     "lot": 0.5,
     "price_open": 102.36,
     "price_close": 102.44,
     "stop_loss": 99.25,
     "take_profit": 103.25 
    },
    {

How to read in an array?

 

Do you give valid json to the parser?

Everything works with your data

  string in="{ \"array\": [ { \"symbol\": \"USDJPY\", \"type\": \"Buy\", \"lot\": 0.5, \"price_open\": 102.36, \"price_close\": 102.44, \"stop_loss\": 99.25, \"take_profit\": 103.25 }, { \"symbol\": \"EURUSD\", \"type\": \"Sell\", \"lot\": 0.2, \"price_open\": 1.1044, \"price_close\": 1.1252, \"stop_loss\": 1.1434, \"take_profit\": 1.0922 } ] }";
  CJAVal js(NULL,jtUNDEF);
  js.Deserialize(in);
  string out="";
  js.Serialize(out);
  Print(out);
 
Alexei, thank you very much! I forgot to wrap it in braces.....
 

Question from a "dummy".

How can I get the value of a key without resorting to the key lookup method?

virtual CJAVal *CJAVal::FindKey(string akey) 
 
Dennis Kirichenko:

Question from a "dummy".

How can I get the value of a key without resorting to the findkey method?

Only by knowing the full path to the key, but findkey will be used implicitly.

double d=jo["order"]["profit"];

double d=ja["array"].m_e[0]["profit"];

---

otherwise, access the m_e array directly, knowing the exact index.

 

Hello. Where can I read about all the functions of your library? The other day I had to solve the problem of interacting with one of the Internet resources, the response from which is returned in JSON format. Your library helped me to save time and not to deal with JSON parsing, for which I thank you very much! But I would like to understand the functions of the library more deeply. I didn't find any description of the library function.

And one more question: in the response from the service in one of the fields is a small description in Cyrillic, but JSON service encodes this text as follows: "description": "\u041d\u043e\u0432\u043e\u0435\u0432\u0432\u0435\u0440\u0441\u0438\u0438 v.2\r\n1.\u0418\u0437\u043c\u0435\u043d\u0435\u043d \u0434\u0438\u0437\u0430\u0439\u043d \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0439 \u043f\u0430\u043d\u0435\u043b\u0438\r\n2.\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043c\u0438\u043d\u0438\u043f\u0430\u043d\u0435\u043b\u044c\r\n3.\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0433\u043e \u0441\u0447\u0435\u0442\u0430\r\n4.\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438\r\n\r\n"

Is it possible to translate this text into the required format with the help of your biblioteca?

Thank you in advance!

 

libe has only two main functions

Serialisation and Deserialisation.

Everything else is overloaded operators, setting and reading arrays

---

this escaped text can be converted.

I will add parsing to Unescape function in the next version.

 

updated to 1.05

the text from your example will be converted to

{"description": "New in version v.2\r\n1.Redesigned trading panel\r\n2.Added mini panel\r\n3.Added balance display for selected trading account\r\n4.Fixed some bugs"}

---

while the admins are updating the codebase, you can download the attached one.

Files:
jason.mqh  30 kb
 
o_O:

updated to 1.05

the text from your example will be converted to

{"description": "New in version v.2\r\n1.Redesigned trading panel\r\n2.Added mini panel\r\n3.Added balance display for selected trading account\r\n4.Fixed some bugs"}

---

while the admins are updating the codebase, you can download the attached one.

Thank you so much! So I can now remove the decoder I've already written from Owl. Let everything be in one library! Very fast response! Many thanks!