How to get Specific element from JSON file by Calling API from objectscript?
Hi
Following API:
http://api.aladhan.com/v1/gToH?date=24-09-2021
is returning following JSON response:
{"code":200,"status":"OK","data":{"hijri":{"date":"16-02-1443","format":"DD-MM-YYYY","day":"16","weekday":{"en":"Al Juma'a","ar":"\u0627\u0644\u062c\u0645\u0639\u0629"},"month":{"number":2,"en":"\u1e62afar","ar":"\u0635\u064e\u0641\u064e\u0631"},"year":"1443","designation":{"abbreviated":"AH","expanded":"Anno Hegirae"},"holidays":[]},"gregorian":{"date":"24-09-2021","format":"DD-MM-YYYY","day":"24","weekday":{"en":"Friday"},"month":{"number":9,"en":"September"},"year":"2021","designation":{"abbreviated":"AD","expanded":"Anno Domini"}}}}
How can I get "hijri":{"date":"16-02-1443" portion from response JSON by calling above API by passing parameter date=24-09-2021 from objectscript?
Thanks
Hi Muhammad,
Create following class :
and call it like :
And if you just want a function to return hijri dates, you van try following build-in $zdate function :
You can also try ,18 which gives 16 Safar 1443
Hi Danny Wijnschenk
Can you please check the below error
Hi Muhammad,
Remove the 'Extends %Net.HttpRequest' : it is not needed to inherit from this class.
Since the method Get is already defined in that class, it gives a compiler error when you overwrite a class with a different signature (classmethod).
Thanks Danny Wijnschenk ·
assuming, the variable jsonStr contains the response from the API, then
write jsonStr ---> {"code":200,"status":"OK","data":... set object={}.%FromJSON( jsonStr ) write object.data.hijri.date
That's all.
The '%FromJSON' class is only available in IRIS ?
.png)
%FromJSON is not a class, it's a method of %DynamicObject and is available in IRIS and for Cache version 2016.2 and later.