Mahlika
Mahlika

Reputation: 29

I can't parse JSON data with PHP Foreach

I tried a few methods but I could not reach the desired result. I could not parse the data from Json as foreach.

$params();
$client = new SoapClient('http://example.com/services?wsdl');
$return = $client->ServiceResp($params);
foreach($return as $turn){
    print_r($turn->returnValue);
}

Output:

{
    "returnValue": {
        "personelInformation": {
            "kimlikTipi": "x",
            "kimlikNo": "x",
            "adi": "xxxx",
            "soyadi": "xxx",
            "ilKodu": "0",
            "ilceKodu": "0",
            "uyruk": "1",
            "mernisBilgisi": "0",
            "oid": "xxxxx",
            "created": "Kas 21, 2017",
            "createdBy": "admin"
        },
        "adres": [],
        "iletisim": [{
            "kisiOid": "xxxxxx",
            "iletisimTercihi": " ",
            "odaBorsaNo": "xxxx",
            "odaBorsaSubeNo": "xxxx",
            "oid": "xxxxxx",
            "created": "Kas 17, 2017",
            "createdBy": "Admin"
        }],
        "telefon": [],
        "eposta": [],
        "ortaklar": [],
        "temsilciler": [],
        "ilgililer": []
    }
}

The information comes in this way, but for example I can't get the staff information part

Upvotes: 0

Views: 45

Answers (1)

John Conde
John Conde

Reputation: 219804

You're almost there. Just use json_decode() to convert that into an object that you can access the properties:

$person = json_decode($turn->returnValue);
echo $person->returnValue->personelInformation->created;

Outputs:

Kas 21, 2017

Demo

Upvotes: 1

Related Questions