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

 

You already know the example of the reference to WebRequest() - and how it turns the loaded data into something readable?

Only then can you analyse the Jason text.

Dokumentation zu MQL5: Netzwerkfunktionen / WebRequest
Dokumentation zu MQL5: Netzwerkfunktionen / WebRequest
  • www.mql5.com
WebRequest - Netzwerkfunktionen - Nachschlagewerk MQL5 - Nachschlagewerk über die Sprache des algothitmischen/automatischen Handels für MetaTrader 5
 
Carl Schreiber #:

You already know the example of the reference to WebRequest() - and how it turns the loaded data into something readable?

Only then can you analyse the Jason text.

Okay, I have now changed it slightly. That has already helped me a lot.

The message via print reads:

2022.12.21 20:20:48.718 jason_test (GER40,H1) The file was downloaded successfully, size 17 bytes.

Which for me means there is a response from the server that I just have to analyse somehow. And a file called url was created which actually contains the answer I was looking for.

Thank you Carl for your help
 

Can you update Add some function likes

JAval j1; j1.Add(1);
j1["a"] = 1;
j1["b"] = 2;


can you Add this functions?

j1.Del("a");
j1.Pop();
j1.shift();
j1.sort();
j1.sort();
 

After the next update it stopped working. In the log - line numbers with errors:

Build 3756.

 

There's a structure like this

[

{

"ticket":671073362

},

{

"ticket":111111111

}

]


I want to get 2 items. Both the first ticket and the second one.

string js = "{\"ticket\":671073362\"},{\"ticket\":111111111}";

jv.Deserialize(js);

Print( jv["ticket"].ToStr());

This way I only get access to the first one. How to get access to the second and subsequent ones, if there are any?

This problem was discussed here https://www.mql5.com/ru/forum/63015/page3#comment_2844920, but there the author wrapped such a structure in a named array, like this.

string js = "{\"array\":[{\"ticket\":671073362},{\"ticket\":111111111}]}";

jv.Deserialize(js);

for(int i = 0; i < ArraySize(jv["array"].m_e); i++)
   {
      Print(jv["array"].m_e[i]["ticket"].ToInt());
   }

That's how everything is found. but what do I do if I can't change the json structure? How to get this array and go through the elements?

 
Nikita Chernyshov #:

There's this structure

[

{

"ticket":671073362

},

{

"ticket":111111111

}

]

...

The specified string does not match the structure given at the beginning and is not a valid json string:

string js = "{\"ticket\":671073362\"},{\"ticket\":111111111}";

It should be:

string js = "[{\"ticket\":671073362},{\"ticket\":111111111}]";

This remark is only on the specification of the json-a, without regard to how it is implemented in a particular library. I use a different one.

 
Stanislav Korotky #:

The specified string does not match the structure given at the beginning and is not a valid json string:

Should be:

This remark is only on the json-as-specification, without regard to how it is implemented in a particular library. I use a different one.

well that's right, it's missing squares, but it doesn't help with them)

 
too many arguments for function-like macro 'DEBUG_PRINT_KEY' JAson.mqh 391 40
if (type != jtUNDEF) { DEBUG_PRINT_KEY(); return false; }  // if value already has type, then this is an error

   see declaration of macro 'DEBUG_PRINT_KEY' JAson.mqh

#ifdef DEBUG
    #define DEBUG_PRINT_KEY() Print(key+" "+string(__LINE__))
#else
    #define DEBUG_PRINT_KEY()
#endif

This warning is coming up on latest mql5 compilation

Any idea how to fix?

 
Arpit T #:
Any idea how to fix?

Remove the parenthesis

if (type != jtUNDEF) { DEBUG_PRINT_KEY; return false; }  // if value already has type, then this is an error
#ifdef DEBUG
    #define DEBUG_PRINT_KEY Print(key+" "+string(__LINE__))
#else
    #define DEBUG_PRINT_KEY
#endif
 
Manuel Alejandro Cercos Perez #:

Remove the parenthesis

fixed, thanks

I am attaching fixed code here

Files:
JAson_1.13.mqh  45 kb