I have a JSON string that I'm trying to use to make a webrequest
When, Print to see how it looks like. I get
I have tried to change json format and fix a line or two, but nothing seems to change
I have a JSON string that I'm trying to use to make a webrequest
When, Print to see how it looks like. I get
I have tried to change json format and fix a line or two, but nothing seems to change
Whatever, the posted code and log are useless to help. The WebRequest code would be needed at least.
Why is there so much additional space at the bottom of your messages ?
I've cleaned it up. I think it is because @Dominik Christian Egert usually types it out on a mobile phone.
I've cleaned it up. I think it is because @Dominik Christian Egert usually types it out on a mobile phone.
Thank you. Yes, I do use the mobile web page. Sometimes I have multiple CRs at the end...
But to be able to post at all, I first need to copy-paste a line with a CR in it, else my comment goes into the citation box.
Whatever, the posted code and log are useless to help. The WebRequest code would be needed at least.
Why is there so much additional space at the bottom of your messages ?
Thanks for the response. I couldn't post the entire webrequest code because the issue seems to be with the way MQL5 interprets json object, the Webrequest had nothing to do with the error, the error it is in the json part, I was able to fix the issue by serializing the json object using this library https://www.mql5.com/en/code/13663 that Fernando Carreiro recommended in other forum post. Here is how I did it
string headers = "Content-Type: application/json; charset=utf-8"; int timeout = 10000; char res[]; string res_header; string url = "http://127.0.0.1:5000/api/write"; CJAVal jv; jv["time"]=(string)time; jv["type"]=IntegerToString(type); jv["volume"]=(string)volume; jv["stoploss"] = (string)stoploss; jv["takeprofit"] = (string)takeprofit; jv["price"] = string(price); //--- serialize to string char data[]; ArrayResize(data, StringToCharArray(jv.Serialize(), data, 0, WHOLE_ARRAY)-1); //--- send data char res_data[]; string res_headers=NULL; int ret = WebRequest("POST", url, headers, timeout, data, res_data, res_headers); if (ret == -1) { Print("Failed to Initiate WebRequest Err=",GetLastError()); return false; } Print("Http Response code =",ret);
![JSON Serialization and Deserialization (native MQL) JSON Serialization and Deserialization (native MQL)](https://c.mql5.com/36/70/json-serialization-and-deserialization.jpg)
- www.mql5.com
Thanks for the response. I couldn't post the entire webrequest code because the issue seems to be with the way MQL5 interprets json object, the Webrequest had nothing to do with the error, the error it is in the json part, I was able to fix the issue by serializing the json object using this library https://www.mql5.com/en/code/13663 that Fernando Carreiro recommended in other forum post. Here is how I did it
Of course it has to do with WebRequest() and how your data are provided, as you proved yourself. Not with "the way MQL5 interprets json object".
string json = "{\r\n" "\"time\": \"2023-06-06 10:00:00\",\r\n" "\"type\": 2,\r\n" "\"volume\": 0.02,\r\n" "\"stoploss\": 1.2000,\r\n" "\"takeprofit\": 1.2500,\r\n" "\"price\": 1.2200\r\n" "}";
Anyway, good you found a solution.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
When, Print to see how it looks like. I get
I have tried to change json format and fix a line or two, but nothing seems to change