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

 

I have received the following string from an http request:

{"records":[{"id":"rec4haaOncoQniu8U","fields":{"orders1":5},"createdTime":"2020-02-08T09:08:22.000Z"}]}

I am not understanding how I can process and separate the values of the json in mql4 using the "JAson.mqh " library, located here: https://www.mql5.com/en/code/13663

I need the values of "orders1" located under "fields" ,   value = 5.

the only "KEYS" that changes are the keys within the "fields" values, all other keys are constants.

i would like to be able to get the values with something like this:

string value1 = Result[0].["fields"].["orders1"]; //5

string value2 = Result[0].["fields"].["orders2"];

Please let me know what I can do.

Thanks

 
Eli Mizrahi:

Do not double post!

Your other post has been deleted.

 

Help me, the line on the site where I'm trying to get information is like this:
"{\"version\":\"0.1\",\"timestamp\":1588516629,\"bycompany\":{\"XTrade\"
Before, there was no "\" sign and I got all the data through this library without any problems, now there is an error.
I tried to remove it in the editor, but I got an error.

string a = "\" ; '' - double quotes are needed

That is, I can't remove the slanted line on my own.

Can you tell me if this code can't cope with this error?


 
Roman Starostin:

Tried to remove it in the editor, but the error.

string a = "\" ; '' - double quotes are needed

So I can't remove the slanted line on my own.

Can you tell me if this code will not be able to cope with it?

It says"double quotes are needed."

You have to write a double backslash "\\\", not a single backslash.

 

I am using the Telegram api and then deseriazle the text. My problem is that there is a carriage return inside the json after "update_id" structure and the deserialise stops with no error


{"ok":true,"result":[{"update_id":568022205,
"channel_post":{"message_id":434,"chat":{"id":-1001436032340,"title":"FORTUNA","type":"channel"},"date":1588890767,"reply_to_message":{"message_id":298,"chat":{"id":-1001436032340,"title":"FORTUNA","type":"channel"},"date":1588753581,"text":"text","entities":[{"offset":67,"length":11,"type":"mention"}]},"text":"this is the text"}}]}

My code is 

string out;
      string url=StringFormat("%s/bot%s/getUpdates",TELEGRAM_BASE_URL,m_token);
      string params=StringFormat("offset=%d",m_update_id);
      //---
      int res=PostRequest(out,url,params,WEB_TIMEOUT);
      if(res==0)
        {
        
         Print(StringDecode(out));
         //--- parse result
         CJAVal js(NULL,jtUNDEF);
         bool done=js.Deserialize(out);
         if(!done)
            return(ERR_JSON_PARSING);

         bool ok=js["ok"].ToBool();
         if(!ok)
            return(ERR_JSON_NOT_OK);
 

array out of range in 'jAson.mqh' (330,22) Error reported!


Position in:


case '{': // начало объекта. создаем объект и забираем его из js

i0=i+1;

if (m_type!=jtUNDEF) { Print(m_key+" "+string(__LINE__)); return false; }// ошибка типа

m_type=jtOBJ; // задали тип значения

i++; if (!Deserialize(js, slen, i)) { Print(m_key+" "+string(__LINE__)); return false; } // вытягиваем его

return js[i]=='}' || js[i]==0; // Exception here.

break;


Thank you for your help.

2823500551@qq.com

 

hi  this error :


array out of range in 'jAson.mqh' (330,22)  // this error


position:


case '{': // начало объекта. создаем объект и забираем его из js

i0=i+1;

if (m_type!=jtUNDEF) { Print(m_key+" "+string(__LINE__)); return false; }// ошибка типа

m_type=jtOBJ; // задали тип значения

i++; if (!Deserialize(js, slen, i)) { Print(m_key+" "+string(__LINE__)); return false; } // вытягиваем его

return js[i]=='}' || js[i]==0;   // this error  what about are me ?

break;



2823500551@qq.com

 

Hi

Would you please provide me a code to parse this json url?

https://search.codal.ir/api/search/v2/q?&Audited=true&AuditorRef=-1&Category=-1&Childs=true&CompanyState=-1&CompanyType=-1&Consolidatable=true&IsNotAudited=false&Length=-1&LetterType=-1&Mains=true&NotAudited=true&NotConsolidatable=true&PageNumber=1&Publisher=false&TracingNo=-1&search=true;
 
Thank you for a great product! It works well while there is little data, but if the array is more than 1000 rows, the deserialization does not work. Please tell me how to fix it.
 
How can I run through all the elements of a JsonArray?

For example {"ABC":{...}, "DEF":{...}, "GHI":{...}}, I don't know the element names in advance, how can I run through all of them?