using CJAVal to handle messages in json via libzmq

 

Hi all,

I am using ZeroMQ to send messages between MT5 and a bunch of applications I have in C#  

I am trying to figure out how to deserialize the data coming off the subSocket in MT5 sent in from my C# component.

The attached file shows the what I am doing.

The raw json strings are being received as shown in the attached image but when I try and deserialize into a CJAVal json object everything is null.

  CJAVal jsn;
        
        subSocket.recv(zmqSub, true);
                   
            zmqSub.getData(_data);
           
            pubSocket.send(CharArrayToString(_data));
        
        if(zmqSub.size() > 0) {
                  
            ArrayResize(_data, zmqSub.size());
      
            zmqSub.getData(_data);
      
            string dataStr = CharArrayToString(_data);
            //decodes as
            //{"MessageType":"Heartbeat","SenderId":"{7CCCD085-CF4F-4778-AB8F-DCB194E903D2}","ReceiverId":null,"Topic":"Heartbeat","SubTopic":null,"timestamp":"1578489397.87759","Text":null}
            
            jsn.Deserialize(_data);
            //returns
            //CJAVal{  group:[7] groupName:"" m_lkey:"" m_parent:NULL m_type:jtOBJ m_bv:false m_iv:0 m_dv:0.0 m_prec:5 m_sv:"" }
            
            int mt = StringToInteger(jsn["MessageType"].ToStr());
            
            if(mt == 3) {
                    
                Alert("Heartbeat received from" + jsn["SenderId"].ToStr());
                pubSocket.send("mt == 3 detected");            
            }

The examples I have found are simples calls to Deserialize and the output shown in the examples is extracting the keys correctly.

in my code mt is obviously zero. 

Any clues ?

Files:
CJAVal.png  121 kb
 

So this is a question about this JSON library ?

Your issue is not clear, "everything is null" ? What is null exactly and what are you expecting ?

JSON Serialization and Deserialization (native MQL)
JSON Serialization and Deserialization (native MQL)
  • www.mql5.com
ForecastOscilator_HTF The ForecastOscilator indicator with the timeframe selection option available in the input parameters. Flat_HTF The Flat indicator with the timeframe selection option available in the input parameters. FX5_SelfAdjustingRSI_HTF The FX5_SelfAdjustingRSI...
 

Correct, it is concerning that library.

The string I receive off the wire and pass to Deserialize is {"MessageType":"Heartbeat","SenderId":"{7CCCD085-CF4F-4778-AB8F-DCB194E903D2}","ReceiverId":null,"Topic":"Heartbeat","SubTopic":null,"timestamp":"1578489397.87759","Text":null}

which I can see in the debug window

when I pass that string to jsn.Deserialize and then view that in the debug window it comes out as 

//CJAVal{  group:[7] groupName:"" m_lkey:"" m_parent:NULL m_type:jtOBJ m_bv:false m_iv:0 m_dv:0.0 m_prec:5 m_sv:"" }   

whereas I expect something that I can go   

        int mt = StringToInteger(jsn["MessageType"].ToStr());   
		
	if(mt == 3) {     

           

ie reference each node based on its key value..

 
Quadrant:

Correct, it is concerning that library.

The string I receive off the wire and pass to Deserialize is {"MessageType":"Heartbeat","SenderId":"{7CCCD085-CF4F-4778-AB8F-DCB194E903D2}","ReceiverId":null,"Topic":"Heartbeat","SubTopic":null,"timestamp":"1578489397.87759","Text":null}

which I can see in the debug window

when I pass that string to jsn.Deserialize and then view that in the debug window it comes out as 

//CJAVal{  group:[7] groupName:"" m_lkey:"" m_parent:NULL m_type:jtOBJ m_bv:false m_iv:0 m_dv:0.0 m_prec:5 m_sv:"" }   

whereas I expect something that I can go   

           

ie reference each node based on its key value..

OK it's done by going  

 string val = jsn.FindKey("SenderId").ToStr();

Thanks for taking the trouble to reply.

 

Have you read the discussion that goes with the library ? 

It seems that more people had the issue with blank key's and found a way to solve it..

https://www.mql5.com/en/forum/65320

Libraries: JSON Serialization and Deserialization (native MQL)
Libraries: JSON Serialization and Deserialization (native MQL)
  • 2015.10.12
  • www.mql5.com
JSON Serialization and Deserialization (native MQL): Author: o_O...
 
Marco vd Heijden:

Have you read the discussion that goes with the library ? 

It seems that more people had the issue with blank key's and found a way to solve it..

https://www.mql5.com/en/forum/65320

Ah, thanks for that link. Appreciated. :)

 
Quadrant:

OK it's done by going  

Thanks for taking the trouble to reply.

Quadrant, Hello!


Did it work? Iam trying o read theJson response, but always get null.


CJAVal jv ;

 res=WebRequest("POST",uri,NULL,NULL, 5000, post, ArraySize(post),result, result_header);

 string dados;

 

 dados = CharArrayToString(result,0,-1);

 Print("dados :", dados);

 jv.Deserialize(dados);

 string mt;

 mt = jv ["EA_MAGICO"].ToStr();

Print("EA :", mt);


2020.02.01 10:13:44.816 teste (EURUSD,M15) dados :{"message":[{"MOEDA":"EURUSD","TIMEFRAME":15,"SWAPATIVO":0,"SWAPMOEDA":1,"ALERTA":"True","EA_MAGICO":201900059298,"IDENTIFICADOR_ROB":"EURUSD-15-2.15","ESPERA":500,"META":1000,"PARA":1000,"VALORCORRETAGEM":0,"LOTES":"0.01","AUMENTO1":"True","AUMENT


But I can get the value!! any idea? 


Thanks!