Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

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

author EAcpu | 6 reads | 0 comments |

JSON Serialization and Deserialization (native MQL) - library for MetaTrader 5

JSON Serialization and Deserialization (native MQL) - library for MetaTrader 5

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

Verification code Refresh