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

 
o_o:

What do you mean? You made those array depths yourself.

I did? - No, my imagination doesn't go that far, but this is a concrete example from life, so to speak.

I meant - can't we do without pointers and brainy constructions? I'd like to keep it simple (I'll modestly keep silent about the library code itself).

 
Andrey Dik:

I did? - No, my imagination doesn't go that far, but this is a concrete example from life, so to speak.

I meant can't you do without pointers and brainy constructions?

Where do you want to do without pointers? What exactly do you want? A piece of json in the log? A "want money" button?

 
o_o:

What exactly do you need? A piece of json in the log? A "want money" button?

That's what this is about:

CJAVal* j1=GetPointer(js.m_e[i].m_e[i1]);

how can you guess without knowing the library code what it is and why it should be done to get what you want?! there should be functions like ToDbl() for simple access to data.

As I see, I'm not the only one who is so "clueless".

ss. e.g. m_e - what is this tinny thing? Couldn't it be called, for example, group? or m_key? - Well, it's nothing but groupName! Is it much more letters? - No, but much clearer.

Bottom line: the library is very powerful and works wonders, but it is written in "dry language" and it is better not to look at the code for the faint-hearted, nursing women and children....

 
Andrey Dik:

that's what this is about:

how can one guess, without knowing the library code, what it is and why it should be done to get what he wants?! there should be functions like ToDbl() for simple data access.

As I see, I'm not the only one who is so "clueless".

ss. e.g. m_e - what is this tinny thing? Couldn't it be called, for example, group? or m_key? - Well, it's nothing but groupName! Is it much more letters? - No, but it's much clearer.

Bottom line: the library is very powerful and works wonders, but it is written in "dry language" and it is better not to look at the code for the faint-hearted, nursing women and children....

Maybe you should try another library?

I used to use it before, but it didn't compile on MQL5 (old version).... you need to adapt it... or try a new version...

http://www.lordy.co.nf/mql4/

there was somewhere on the forum about it...

---------------------

here it is...

https://www.mql5.com/en/code/11134

 
Andrey Dik:

that's what this is about:

how can one guess, without knowing the library code, what it is and why it should be done to get what he wants?! there should be functions like ToDbl() for simple data access.

As I see, I'm not the only one who is so "clueless".

ss. e.g. m_e - what is this tinny thing? Couldn't it be called, for example, group? or m_key? - Well, it's nothing but groupName! Is it much more letters? - No, but it's much clearer.

Bottom line: the library is very powerful and works wonders, but it is written in "dry language" and it is better not to look at the code for the faint-hearted, nursing women and children....

So who forced you to go inside the m_e array?

I don't know what you want from the code. And I don't know what kind of task you're developing.

---

First of all, json is a format of data transmission, structure. If you don't understand the structure of the received data, it's not my classes' problem, it's yours. Go to the documentation of your data source and look for understanding there

Secondly - the class implements the basic functions of working with the format - serialisation, storage of structure and convenient handling

If you wanted to get data from a certain array, you would write convenient code.

Print( js["фирма1"]["модельный_ряд1"][0][0].TODbl() );

and not that lengthy bullshit in the form of loops to retrieve the whole structure. I don't know what it was all about.

 
Delta.800:

maybe you should try a different library.

I used to use it before, but it didn't compile on MQL5 for me (old version)... you need to adapt it... or try a new version...

http://www.lordy.co.nf/mql4/

there was somewhere on the forum about it....

---------------------

here it is...

https://www.mql5.com/en/code/11134

Thanks, but I trust Sergeyev's code completely.

I was stupid with the pointers, of course, I apologise. Difficult to read - fii, what a problem...

 

o_o:

Print( js["фирма1"]["модельный_ряд1"][0][0].TODbl() );

and not that lengthy bullshit in the form of loops through the whole structure. I don't know what that was all about.

by group name the data may not exist, or the group is not complete, or the group name is not in the data, or something else... how then?

This way it is easier and clearer and you can always check the size of arrays so that you don't have problems with filling your structures:

js.group [счетчикФирм].group [счетчикМодельногоРяда].group [счетчикМоделей].group [счетчикМодельВизОбъем].ToDbl ());

 

in such variants it is not clear what to do with a non-existent element

like this

js["фирма1"]["модельный_ряд1"][0][0].TODbl()

this way

js.group [countFirms].group [countModelRow].group [countModels].group [countModelVolume].ToDbl ());


if js["firm1"] or js.group [counterFirms] does not appear, what to output ? and whether to output anything at all ?

at this point the null element will be accessed and an error will occur....

 
o_o:

in such variants it is not clear what to do with a non-existent element

like this

js["фирма1"]["модельный_ряд1"][0][0].TODbl()

this way

js.group [countFirms].group [countModelRow].group [countModels].group [countModelVolume].ToDbl ());


if js["firm1"] or js.group [counterFirms] does not appear, what to output ? and whether to output anything at all ?

at this point will be a reference to null element and an error...

There are shelves in a shop, for each genre and author there is a different rack and shelves (structure/s that the programme works with). And there are books (data) that may or may not come to the store.....

And what, every time to redesign the shelves for a new arrival of books? No, of course not.

To address in this way:

js["фирма1"]["модельный_ряд1"][0][0].TODbl()

you need to know the name of the group, and if the group in the incoming data is there, but the name is not there? And if ..... a lot of things can happen...

It's easier to just check the size of the groups of the data and their number, that's all, if at least one size does not coincide with our structures, then the data is broken and there is no point in fiddling with them and find out what exactly is broken in them, just ignore the packet of this data and that's all. There are no problems with access to non-existent (or empty) array cells and there is no uncertainty about the correctness of the arrived data. And the programme will never crash for some reason.

[Deleted]  

Would anyone or the author answer if this is supposed to support nested JSON? That is a CJAVal instance contains a keys '2', and '3' which are another CJAVal instance. Code seems to run but when serialized the keys are blank.

Example, I am getting:

{"":{"sl":5270.98000000,"tp":5285.26000000,"order":2},"":{"sl":5274.80000000,"tp":5289.06000000,"order":3}}

But should be getting 

{"2":{"sl":5270.98000000,"tp":5285.26000000,"order":2},"3":{"sl":5274.80000000,"tp":5289.06000000,"order":3}}