Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/12/2012, 17:53
alvarols
 
Fecha de Ingreso: diciembre-2008
Mensajes: 738
Antigüedad: 15 años, 10 meses
Puntos: 15
Error al jalar jSon desde PHP: Object of class stdClass could not be converted

Estoy tratando de jalar información desde un archivo jSON. En este caso uso la API de Twitter. De cada Tweet puedo sacar varios valores con éxito, pero el que tiene que ver con "geo" me saca ese error.

Este es un extracto del Tweet en el jSON:

"from_user_name":"Juan Escutia","geo":{"coordinates":[20.721799,-103.391608]

Por ejemplo, el nombre "from_user_name" lo muestra normal. Pero "geo" es el que jala el error. Así es como estoy sacando las variables:

Código PHP:
Ver original
  1. <?php
  2. $data = 'http://search.twitter.com/search.json?q=from:lauharo';
  3. $feed = file_get_contents($data); //Getting the JSON data.
  4.  
  5. $valid_data = json_decode($feed); // Converting the JSON data to PHP format.
  6. $valid_data = $valid_data->results; // Valid data now with just the tweet result.
  7.  
  8. // Printing out the feed's data in our required format.
  9. print '<pre>';
  10. foreach ($valid_data as $key=>$value) {
  11.   print '<div id="twitter-data-container">';
  12.   print '<p>' . $value->text . '</p>';
  13.   print '<p>' . $value->geo . '</p>';
  14.   print '</div>';
  15. }
  16. print '</pre>';
  17. ?>