How to Retrive Array Data from WebRequest Response
I am telling you a trick of the profs: place the cursor on WebRequest and press F1 - you'll find the direct HowTo of this function with an example to get the content ready to be copied ... ;)
As Fernando said , you will need a json library . (i think there is one built in i'm attaching one anyway)
Then you will look up how your data provider serves the data and format your extraction accordingly
So if the data vendor has this format , for example :
you will adapt your extraction like this
CJAVal loader; loader.Deserialize(CharArrayToString(result),CP_UTF8); //# results int venues_found=(int)StringToInteger(loader["results"].ToStr()); //loop for(int s=0;s<venues_found;s++) { string _venue_id=loader["response"][s]["id"].ToStr(); string _venue_name=loader["response"][s]["name"].ToStr(); string _venue_address=loader["response"][s]["address"].ToStr(); string _venue_city=loader["response"][s]["city"].ToStr(); string _venue_capacity=loader["response"][s]["capacity"].ToStr(); string _venue_surface=loader["response"][s]["surface"].ToStr(); string _venue_image=loader["response"][s]["image"].ToStr(); }
Files:
jason_with_search.mqh
38 kb
When I print out "Server response", I can see the array with data inside are retrieved successfully. But when I tried to retrieve one of the array element with "result[1]", it prints out "91"? Not sure what went wrong.