2016-04-13 19 views
-1

Aramada bir diziye veri alıyorum (JSON). Kullanmak:Diziden veri oku

$jsonurl = "https://api.openarch.nl/1.0/records/search.json?name=baltus&lang=en&number_show=5&archive=rhl&start=0"; 
$jsondata = file_get_contents($jsonurl); 
$json = json_decode($jsondata,true); 

$i=0; 
foreach ($json as $item) 
{ 
    print_r($item)[$i]; 
$i++; 
} 

I dış diziler yazdırabilir ama iç [dokümanlar] döngü, bir tablodaki ekran ve bir değişken dolum işlemi için kullanılacak verileri almak için bir dizi olamaz.

Array 
( 
[query] => Array ([archive] => Regionaal Historisch Centrum Limburg [name] => baltus [only_results_with_scans] => [start] => 0 [number_show] => 5 [sort] => 1 [language] => en) 

[response] => Array ( 
    [number_found] => 1388 
    [docs] => Array (
     [0] => Array ([identifier] => 90cbe7d7-1eca-5654-feb5-d397f11b0412 [archive] => Regionaal Historisch Centrum Limburg [personname] => Adrian Baltus van Tienhoven [relationtype] => Vader [eventtype] => Geboorte [eventdate] => Array ([day] => 19 [month] => 11 [year] => 1891) [eventplace] => Venlo [sourcetype] => BS Geboorte) 
     [1] => Array ([identifier] => 93a07a53-9b80-9d14-196b-be30a6e17c21 [archive] => Regionaal Historisch Centrum Limburg [personname] => Adrianus Baltus van Tienhoven [relationtype] => Vader [eventtype] => Geboorte [eventdate] => Array ([day] => 26 [month] => 9 [year] => 1893) [eventplace] => Venlo [sourcetype] => BS Geboorte) 
     [2] => Array ([identifier] => cb92d489-228a-dc8b-6a04-3273452b4994 [archive] => Regionaal Historisch Centrum Limburg [personname] => Adrianus Baltus van Tienhoven [relationtype] => Vader [eventtype] => Overlijden [eventdate] => Array ([day] => 24 [month] => 11 [year] => 1891) [eventplace] => Venlo [sourcetype] => BS Overlijden) 
     [3] => Array ([identifier] => 2ef73050-76ac-362b-213d-1cab5a1199f2 [archive] => Regionaal Historisch Centrum Limburg [personname] => Agnes Baltus [relationtype] => Moeder [eventtype] => Overlijden [eventdate] => Array ([day] => 27 [month] => 1 [year] => 1869) [eventplace] => Posterholt [sourcetype] => BS Overlijden) 
     [4] => Array ([identifier] => 3c8dc193-4753-172d-2935-24a2f2162732 [archive] => Regionaal Historisch Centrum Limburg [personname] => Alexander Baltus [relationtype] => Vader van de bruidegom [eventtype] => Huwelijk [eventdate] => Array ([day] => 19 [month] => 7 [year] => 1842) [eventplace] => Beek [sourcetype] => BS Huwelijk)))) 
+0

'foreach ($ öğe olarak [ 'yanıtı'] [ 'docs'] $ json) {[$ öğeyi echo 'tanımlayıcı']; } ' – AbraCadaver

+1

Düzgün biçimlendirmeyle yazdırırsanız, yuvalama düzeyini kolayca söyleyebilmeniz gerekir. – Barmar

+1

@AbraCadaver Bunu bir yanıt olarak göndermelisiniz, çünkü bunun yerine bir sürü sahte cevap alıyoruz. – Barmar

cevap

1

Döngü yuvalanmış dizi ve bu dizi içinde istediği anahtarlara erişim:

foreach($json['response']['docs'] as $item) { 
    echo $item['identifier']; 
    // etc... 
}