Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php/json] Jak wyczytać atrybuty z json
log
post
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 20.02.2007

Ostrzeżenie: (0%)
-----


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. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
kriqs
post
Post #2





Grupa: Zarejestrowani
Postów: 148
Pomógł: 0
Dołączył: 31.05.2006

Ostrzeżenie: (0%)
-----


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


--------------------
Pozdrawiam
kriqs

mam nadzieje ze pomoglem :)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 15:39