JSON Serialization and Deserialization (Native MQL) - MetaTrader 5 Library - MT4/MT5 Resources


Serialization and deserialization of JSON protocol. The code was ported from the high-speed С++ library.
The string is in , out ; CJAVal js(NULL, jtUNDEF); Boolean value b; //--- print( "JASon deserialization example:" ); in = "{\"a\":[1,2]}" ; out = "" ; // Input data example b = js.deserialization( in ); // deserialize js.serialization( out ); // serialize print again ( in + '' -> " + out ); // Output to compare //--- print( "JASon example serialization:" ); js[ “Test” ]= 1.4 ; // Input data example Go out = ”” ; js.Serialize( go out ); // Serialize print( go out ); // Output
Practical example: website authorizes and parses response
CJAVal Joint Venture; joint venture[ "login" ]= "login" ; //login joint venture[ "password" ]= "pass" ; //password //--- serialize to string {"login":"Login","password":"Pass"} Character data []; array resize (data, string to character array (jv.Serialize(), data, 0 , entire array ) -1 ); //--- send data char res_data[]; string resource headers = void ; integer r = networkRequest( "post" , "http://my.site.com/Authorize" , "Content-Type: text/plain\r\n" , 5000 , data, res_data, res_headers); //--- Suppose the answer is {" access token ":"ABRAKADABRA","session_id":124521} //--- Get AccessToken jv.Deserialize(res_data); StringAccessToken =jv[ "Access Token" ].ToStr();
You can express your gratitude by sending examples of implementing MQL to use web resources. Share your experience using JSON in MQL.
Attachment download
📎 jason_test.mq5 (5.85 KB)
📎 jason.mqh (30.59 KB)
Source: MQL5 #13663
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •