PHP json (besleme) ayrıştırmak nasıl

4 Cevap php

I have a json feed from zoho : here, you can acces the same file unencrypted here I like to be able to display and parse the data from that feed int html

Dün benzer bir soru sormak var, ama çözüm bir javascript oldu, ve java devre dışı istemci tarafı olan yüzden ben php ile gidecek ... göstermek için hiçbir şey yol açabilir. Ben bir var ama besleme ayrıştırmak olabilir? ....

Soru 2. Bir json yem yakalamak, ve (yedekleme amacıyla) dosyası olarak kaydedin, böylece site aşağı giderseniz i (küçük olasılıklarımız) bu dosyayı acces olacak mümkün mü

4 Cevap

json_decode will convert the json string to object form by default, in order to use it as associative array you have to specify 'true' as second parameter, example below. json_decode($json,true)

Referans: php Json_decode reference

Ne istediğinizi yapmak için basitleştirilmiş kod.

$sJson = file_get_contents('http://example.com/path/to/feed.json');
file_put_contents('/path/to/file', $sJson);
$oJson = json_decode($sJson);	
var_dump($oJson);

URL Korumalar kapalı ya da kimlik doğrulama üstbilgileri (veya belirlenen diğer özel başlıklarını) ihtiyacınız varsa, file_get_contents yerine curl kütüphaneleri kullanabilirsiniz.

I / erişim bazı değişken baskı yapabilmek istiyorum ama diziye wright şekilde erişmek için hile var gibi olamaz

önceki cevap dayalı:

$json = file_get_contents('http://produits-lemieux.com/json.txt');
$data = json_decode($json);
//var_dump($data);
print_r($data['prod_ingredient']); //dont work !... error 
print_r($data['Liste_des_produits1'].prod_ingredient[0]); //dont work !... error