4 Kasım 2008, Salı
PHP bir JSON işleme veri Nesnesi
Trendleri Twitter Arama API JSON veri.
Dosyayı kullanarak kapma:
$jsonurl = "http://search.twitter.com/trends.json";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);
Nasıl bu nesneden veri ile iş yapmam. Bir dizi? Gerçekten [adı] değerleri veri ayıklamak için yeterlidir.
JSON nesne içerir:
stdClass Object
(
[trends] => Array
(
[0] => stdClass Object
(
[name] => Vote
[url] => http://search.twitter.com/search?q=Vote
)
[1] => stdClass Object
(
[name] => Halloween
[url] => http://search.twitter.com/search?q=Halloween
)
[2] => stdClass Object
(
[name] => Starbucks
[url] => http://search.twitter.com/search?q=Starbucks
)
[3] => stdClass Object
(
[name] => #flylady
[url] => http://search.twitter.com/search?q=#flylady
)
[4] => stdClass Object
(
[name] => #votereport
[url] => http://search.twitter.com/search?q=#votereport
)
[5] => stdClass Object
(
[name] => Election Day
[url] => http://search.twitter.com/search?q="Election Day"
)
[6] => stdClass Object
(
[name] => #PubCon
[url] => http://search.twitter.com/search?q=#PubCon
)
[7] => stdClass Object
(
[name] => #defrag08
[url] => http://search.twitter.com/search?q=#defrag08
)
[8] => stdClass Object
(
[name] => Melbourne Cup
[url] => http://search.twitter.com/search?q="Melbourne Cup"
)
[9] => stdClass Object
(
[name] => Cheney
[url] => http://search.twitter.com/search?q=Cheney
)
)
[as_of] => Mon, 03 Nov 2008 21:49:36 0000
)
CEVAP
4 Kasım 2008, Salı
Böyle bir şey mi yani?
<?php
$jsonurl = "http://search.twitter.com/trends.json";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);
foreach ( $json_output->trends as $trend )
{
echo "{$trend->name}\n";
}
Bunu Paylaş:
Nasıl json YAZILAN veri nesnesi olarak...
Mağaza JSON HTML jQuery veri öznitelik...
Nasıl yeni PostgreSQL JSON veri türü i...
ASP.NET MVC JSON Veri gönderme...
JSON Dize ikili Veri. Bir şey Base64 d...