Retrieve Specific Data from a JSON Webrequest

 
I'm learning MQL4, but yet to understand array functions well.
I have a piece of data which I retrieved with  Webrequest function. It looks like this:

{"error":false,"message":"","symbols":[{"name":"EURUSD","shortPercentage":8,"shortVolume":5239.1},{"name":"GBPUSD","shortPercentage":22,"shortVolume":2001.12},{"name":"USDJPY","shortPercentage":87,"shortVolume":22101.26},{"name":"GBPJPY","shortPercentage":38,"shortVolume":1354.54}

For a currency pair such as USDJPY in the above data, I wish to retrieve the value of shortPercentage into an integer variable.

I will appreciate if someone can help with the code to use.
 

Hello you can use the search function to discover there are 11 pages about JSON subject.

https://www.mql5.com/en/search#!keyword=json&module=mql5_module_forum

Search - MQL5.community
Search - MQL5.community
  • www.mql5.com
Searching is based on morphology and is insensitive to case. All letters, no matter of their case, will be processed as lowercase. By default, our search engine shows pages, that...
 

Im not sure because you did not post any code.

But if the result from your call is always in the same format you can roll your own slicer with standard string functions.

 

Pardon me, Marco. I pasted the code. But wasn't familiar with the interface.

I've updated the post with the code.

 

peterbabs
:

Thank you for the link, Marco vd Heijden!

But I'm not getting the desired result

Print result for CurrencyPair returns blank
Print result for ShortPercentage returns 0


I've not been able to figure it out.

What do you think I'm doing wrong.

As per your json in the first post, you need to point "symbols" array first, then get their items, and since percentage is an integer, you may call ToInt() instead of ToDbl(),  something like this:
string CurrencyPair0=json["symbols"][0]["name"].ToStr(); 
int ShortPercentage0=json["symbols"][0]["shortPercentage"].ToInt();
 
Mohammad Hossein Sadeghi:
As per your json in the first post, you need to point "symbols" array first, then get their items, and since percentage is an integer, you may call ToInt() instead of ToDbl(),  something like this:

Thanks, Mohammad!

You have solve a problem for me that has taken me 2weeks...

I'm grateful!!!!!!!!

 
peterbabs:

Thanks, Mohammad!

You have solve a problem for me that has taken me 2weeks...

I'm grateful!!!!!!!!

You're welcome.