Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php/json] Jak wyczytać atrybuty z json
Forum PHP.pl > Forum > Przedszkole
log
To jest przykład ze strony IBM. Chciałbym wiedzieć jak moge wyczytać wartość @attributes.


  1. $books = '{
  2.   "books" : {
  3.      "book" : [ {
  4.         "@attributes" : {
  5.            "id" : "1"
  6.         },
  7.         "title" : "Code Generation in Action",
  8.         "author" : {
  9.            "first" : "Jack", "last" : "Herrington"
  10.         },
  11.         "publisher" : "Manning"
  12.      }, {
  13.         "@attributes" : {
  14.            "id" : "2"
  15.         },
  16.         "title" : "PHP Hacks", "author" : {
  17.            "first" : "Jack", "last" : "Herrington"
  18.         },
  19.         "publisher" : "O'Reilly"
  20.      }, {
  21.         "@attributes" : {
  22.            "id" : "3"
  23.         },
  24.         "title" : "Podcasting Hacks", "author" : {
  25.            "first" : "Jack", "last" : "Herrington"
  26.         },
  27.         "publisher" : "O'Reilly"
  28.      }
  29.   ]}
  30. }';
  31.  
  32. $val = json_decode($books);
  33.  
  34. echo $val->books->book."\n";
  35.  
  36. ?>
kriqs
witam

a musi byc ta m@lp@ questionmark.gif smile.gif bo bez tego to :

foreach( $val->books->book as $ob )
{
var_dump( $ob->attributes->id );
}

a tak to nie wiem czy sie da smile.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.