how to write code that parse my json that I got with webrequest
I take json data from website using webrequest now How can I parse this json code for use my trading decisions
There is a built in Json library by default i think in the includes folder .
i'm attaching a file (with some personal additions)
And here is a codebase link with an example :
- www.mql5.com
//+------------------------------------------------------------------+ //| forex-robot.mq5 | //| Copyright 2023, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2023, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #include "json.mqh" //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- string cookie=NULL,headers; char post[],result[]; string url = "https://webhook.site/85564fea-5205-4a28-b2b8-45aff056310c"; // Make a GET request to the webhook.site URL int res=WebRequest("GET",url,cookie,NULL,500,post,0,result,headers); // Print the JSON data Print("Web request result: ", res, ", error: #", (res == -1 ? GetLastError() : 0)); } //+------------------------------------------------------------------+
shouldn't I use it like this when I write I got this error message
can't open "C:\Users\FS\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Scripts\json.mqh" include file forex-robot.mq5 10 11
okay sir I put the code that you sent me jason_with_search.mqh how can I acces the json codes and parse which I got with webrequest
I try to say which codes should I write
okay sir I put the code that you sent me jason_with_search.mqh how can I acces the json codes and parse which I got with webrequest
I try to say which codes should I write
Do you have an example response the server sends ? (open the test.txt after running this)
void OnStart() { //--- string cookie=NULL,headers; char post[],result[]; string url = "https://webhook.site/85564fea-5205-4a28-b2b8-45aff056310c"; // Make a GET request to the webhook.site URL int res=WebRequest("GET",url,cookie,NULL,500,post,0,result,headers); // Print the JSON data Print("Web request result: ", res, ", error: #", (res == -1 ? GetLastError() : 0)); string test_alert=CharArrayToString(result,0,ArraySize(result),CP_UTF8); CJAVal loader; loader.Deserialize(test_alert,CP_UTF8); //you then go into the data like accessing arrays , but first for a test you output what the result is bool am_i_testing=true; if(am_i_testing){ int f=FileOpen("Test.txt",FILE_WRITE|FILE_TXT); FileWriteString(f,test_alert); FileClose(f); } }
Sir I runned the code that you sent me but I can't find the path of the Test.txt where is text created.
Maybe text file even dont create.
What is the web request result that is printed in the Experts tab on the bottom ?
does it say 503?
I got http 200 status code means successful meanwhile we are trying to get data, how can we get json data from webhook.site?
I think I have a connection with site right now even I can send post requests there but problem I cant take the json data this is my only question.
Thank you,
I got http 200 status code means successful meanwhile we are trying to get data, how can we get json data from webhook.site?
I think I have a connection with site right now even I can send post requests there but problem I cant take the json data this is my only question.
Thank you,
Are you sure you are not getting an empty response ?
Place an :
Alert(test_alert);
after
string test_alert=CharArrayToString(result,0,ArraySize(result),CP_UTF8);
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
how to write code that parse my json that I got with webrequest
I take json data from website using webrequest now How can I parse this json code for use my trading decisions