← Back to team overview

dhis2-devs team mailing list archive

Re: DHIS-2 API's

 

Hi Omer Butt,

You can parse/decode this json string by using JavaScript, PHP or Java or
any other languages.



*You can parse by JavaScript as below: *<p id="demo"></p>
<script>
var dhis2JSONObj, x;

dhis2JSONObj =
{"name":"Bannu","children":[{"id":"yvVnd97UiJN"},{"id":"cdlEAe4BMS2"}],"ancestors":[{"id":"osCztkmFYud"},{"id":"KH8VFLnpwWL"}]}
;

x = dhis2JSONObj.name;
document.getElementById("demo").innerHTML = x;

</script>

Result:

​
*You can decode by PHP as below: *

<?php
$json = '{
    "name": "Bannu",
    "children": [{
        "id": "yvVnd97UiJN"
    }, {
        "id": "cdlEAe4BMS2"
    }],
    "ancestors": [{
        "id": "osCztkmFYud"
    }, {
        "id": "KH8VFLnpwWL"
    }]
}';

$obj = json_decode($json);
print $obj->{'name'}; // Bannu
?>

​

*You can parse by Java as below: *

https://examples.javacodegeeks.com/core-java/json/java-json-parser-example/





*If you have any questions or concerns, don’t hesitate to let me know.*

*Best Regards*
*Julhas Sujan*
Senior Java Programmer
Management Science for Health(MSH)
Dhaka, Bangladesh
Cell: +8801989 442856
Skype: julhas08
​
www.msh.org http://siapsprogram.org/wherewework/bangladesh/

On Thu, Aug 24, 2017 at 11:29 AM, Omer Butt <omerbutt2521@xxxxxxxxx> wrote:

> Sir I used that API :
> *:/api/organisationUnits/OYfCChzZ1wx.json?fields=ancestors,children,name*
>
> *Response :*
> {"name":"Bannu","children":[{"id":"yvVnd97UiJN"},{"id":"
> cdlEAe4BMS2"}],"ancestors":[{"id":"osCztkmFYud"},{"id":"KH8VFLnpwWL"}]}
>
>
> *------------------------------------------------------------------------------------------------------*
> *How Can I get name of the children and ancestors. ??*
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dhis2-devs
> Post to     : dhis2-devs@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dhis2-devs
> More help   : https://help.launchpad.net/ListHelp
>
>

JPEG image

PNG image

PNG image


References