how to write code that parse my json that I got with webrequest - page 5

 
Caner Efe Altıntaş #:

hey guys as you told I solved the content part in the json is there anything wrong? Let it check please.



 Looking good . 

I'd suggest to also add the digits of the asset and the point size , it will help you in the future .

This is how you read it , assuming you saved it as "feed3.json" 

#include "jason_with_search.mqh"

void OnStart(){
//Create Jason object
CJAVal loader;
//file 
int f=FileOpen("feed3.json",FILE_READ|FILE_BIN);
uchar bytes[];
if(f!=INVALID_HANDLE){
FileReadArray(f,bytes,0,FileSize(f));
FileClose(f);
}
string raw=CharArrayToString(bytes,0,ArraySize(bytes),CP_UTF8);
//fill loader with json string 
loader.Deserialize(raw,CP_UTF8);
//now lets say you want to see how many items there are in there 
  int items=ArraySize(loader.m_e);
  Print("Has "+IntegerToString(items)+" items");
  for(int i=0;i<items;i++){
     //method
       string method=loader[i]["method"].ToStr();
     //symbol
       string symbol=loader[i]["content"]["Symbol"].ToStr();
     //direction
       int direction=(int)loader[i]["content"]["Direction"].ToInt();
     //price
       double price=(double)loader[i]["content"]["Price"].ToDbl();
     //volume 
       double volume=(double)loader[i]["content"]["Volume"].ToDbl();
     Print("Item("+IntegerToString(i)+")"+symbol+" [DIR:"+IntegerToString(direction)+"] @"+DoubleToString(price,8)+" Vol."+DoubleToString(volume,8));
     }

}
 
Caner Efe Altıntaş #:

hey guys as you told I solved the content part in the json is there anything wrong? Let it check please.



     },
]

remove the extra comma, it is allowed only followed by another value.

 
Lorentzos Roussos #:

 Looking good . 

I'd suggest to also add the digits of the asset and the point size , it will help you in the future .

This is how you read it , assuming you saved it as "feed3.json" 

Thank you so much.

You helped me so much.

 
Samuel Manoel De Souza #:

remove the extra comma, it is allowed only followed by another value.

thank you so much I fixed it.

 
Alain Verleyen #:
He needs to understand to JSON format to start with, otherwise it's waste of time. I will let you continue if you like.

Thank you so much for your patience.

You helped me so much. appreciate 

 
Samuel Manoel De Souza #:

remove the extra comma, it is allowed only followed by another value.

Nice catch i missed that .

Caner Efe Altıntaş #:

Thank you so much.

You helped me so much.

:)