Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> JSON
szczawik
post
Post #1





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 19.08.2010

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


Witam jak wyświetlić wartości z tego linka?
http://api.jamendo.com/get2/id+name+url+im...ratingweek_desc
Go to the top of the page
+Quote Post
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




json_decode


--------------------
Go to the top of the page
+Quote Post
szczawik
post
Post #3





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 19.08.2010

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


a jak wyświetlić dowolny element?

  1. {"images":{"image":{"title":"","url":"http:\/\/www.last.fm\/music\/Ewa+Farna\/+images\/57591921","dateadded":"Thu, 20 Jan 2011 15:56:58","format":"png","owner":{"name":"maddie_XD","url":"http:\/\/www.last.fm\/user\/maddie_XD","@attr":{"type":"user"}},"sizes":{"size":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/_\/57591921\/Ewa+Farna.png","name":"original","width":"248","height":"371"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/57591921.png","name":"large","width":"126","height":"188"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126s\/57591921.png","name":"largesquare","width":"126","height":"126"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64\/57591921.png","name":"medium","width":"64","height":"96"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34\/57591921.png","name":"small","width":"34","height":"51"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/252\/57591921.png","name":"extralarge","width":"252","height":"377"}]},"votes":{"thumbsup":"38","thumbsdown":"3"}},"@attr":{"artist":"Ewa Farna","page":"1","perPage":"1","totalPages":"224","total":"224"}}}


jak wyświetlić tylko
http:\/\/userserve-ak.last.fm\/serve\/_\/57591921\/Ewa+Farna.png
?
Go to the top of the page
+Quote Post
Ociu
post
Post #4





Grupa: Moderatorzy
Postów: 1 566
Pomógł: 37
Dołączył: 14.05.2003
Skąd: Kraków




  1. $jsonObj = json_decode('{"images":{"image":{"title":"","url":"http:\/\/www.last.fm\/music\/Ewa+Farna\/+images\/57591921","dateadded":"Thu, 20 Jan 2011 15:56:58","format":"png","owner":{"name":"maddie_XD","url":"http:\/\/www.last.fm\/user\/maddie_XD","@attr":{"type":"user"}},"sizes":{"size":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/_\/57591921\/Ewa+Farna.png","name":"original","width":"248","height":"371"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/57591921.png","name":"large","width":"126","height":"188"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126s\/57591921.png","name":"largesquare","width":"126","height":"126"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64\/57591921.png","name":"medium","width":"64","height":"96"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34\/57591921.png","name":"small","width":"34","height":"51"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/252\/57591921.png","name":"extralarge","width":"252","height":"377"}]},"votes":{"thumbsup":"38","thumbsdown":"3"}},"@attr":{"artist":"Ewa Farna","page":"1","perPage":"1","totalPages":"224","total":"224"}}} ');
  2. var_dump($jsonObj);
Go to the top of the page
+Quote Post
szczawik
post
Post #5





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 19.08.2010

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


otrzymałem
  1. object(stdClass)#1 (1) { ["images"]=> object(stdClass)#2 (2) { ["image"]=> object(stdClass)#3 (7) { ["title"]=> string(0) "" ["url"]=> string(51) "http://www.last.fm/music/Ewa+Farna/+images/57591921" ["dateadded"]=> string(25) "Thu, 20 Jan 2011 15:56:58" ["format"]=> string(3) "png" ["owner"]=> object(stdClass)#4 (3) { ["name"]=> string(9) "maddie_XD" ["url"]=> string(33) "http://www.last.fm/user/maddie_XD" ["@attr"]=> object(stdClass)#5 (1) { ["type"]=> string(4) "user" } } ["sizes"]=> object(stdClass)#6 (1) { ["size"]=> array(6) { [0]=> object(stdClass)#7 (4) { ["#text"]=> string(58) "http://userserve-ak.last.fm/serve/_/57591921/Ewa+Farna.png" ["name"]=> string(8) "original" ["width"]=> string(3) "248" ["height"]=> string(3) "371" } [1]=> object(stdClass)#8 (4) { ["#text"]=> string(50) "http://userserve-ak.last.fm/serve/126/57591921.png" ["name"]=> string(5) "large" ["width"]=> string(3) "126" ["height"]=> string(3) "188" } [2]=> object(stdClass)#9 (4) { ["#text"]=> string(51) "http://userserve-ak.last.fm/serve/126s/57591921.png" ["name"]=> string(11) "largesquare" ["width"]=> string(3) "126" ["height"]=> string(3) "126" } [3]=> object(stdClass)#10 (4) { ["#text"]=> string(49) "http://userserve-ak.last.fm/serve/64/57591921.png" ["name"]=> string(6) "medium" ["width"]=> string(2) "64" ["height"]=> string(2) "96" } [4]=> object(stdClass)#11 (4) { ["#text"]=> string(49) "http://userserve-ak.last.fm/serve/34/57591921.png" ["name"]=> string(5) "small" ["width"]=> string(2) "34" ["height"]=> string(2) "51" } [5]=> object(stdClass)#12 (4) { ["#text"]=> string(50) "http://userserve-ak.last.fm/serve/252/57591921.png" ["name"]=> string(10) "extralarge" ["width"]=> string(3) "252" ["height"]=> string(3) "377" } } } ["votes"]=> object(stdClass)#13 (2) { ["thumbsup"]=> string(2) "38" ["thumbsdown"]=> string(1) "3" } } ["@attr"]=> object(stdClass)#14 (5) { ["artist"]=> string(9) "Ewa Farna" ["page"]=> string(1) "1" ["perPage"]=> string(1) "1" ["totalPages"]=> string(3) "224" ["total"]=> string(3) "224" } } }


Co z tym dalej zrobić?
Go to the top of the page
+Quote Post
Ociu
post
Post #6





Grupa: Moderatorzy
Postów: 1 566
Pomógł: 37
Dołączył: 14.05.2003
Skąd: Kraków




Następnie weź kurs php i poczytaj co z tym zrobić.
Dostałeś praktycznie gotowca!

Edit:
Jeżeli nie znasz obiektów, to wynik dostaniesz w postaci tablicy:
  1. $jsonObj = json_decode('{"images":{"image":{"title":"","url":"http:\/\/www.last.fm\/music\/Ewa+Farna\/+images\/57591921","dateadded":"Thu, 20 Jan 2011 15:56:58","format":"png","owner":{"name":"maddie_XD","url":"http:\/\/www.last.fm\/user\/maddie_XD","@attr":{"type":"user"}},"sizes":{"size":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/_\/57591921\/Ewa+Farna.png","name":"original","width":"248","height":"371"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/57591921.png","name":"large","width":"126","height":"188"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126s\/57591921.png","name":"largesquare","width":"126","height":"126"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64\/57591921.png","name":"medium","width":"64","height":"96"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34\/57591921.png","name":"small","width":"34","height":"51"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/252\/57591921.png","name":"extralarge","width":"252","height":"377"}]},"votes":{"thumbsup":"38","thumbsdown":"3"}},"@attr":{"artist":"Ewa Farna","page":"1","perPage":"1","totalPages":"224","total":"224"}}} ', true);
  2. var_dump($jsonObj);
Go to the top of the page
+Quote Post
szczawik
post
Post #7





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 19.08.2010

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


Wyświetliłem w tablicy
  1. $array = (array)json_decode($homepage);

efekt:
  1. (
  2. [images] => stdClass Object
  3. (
  4. [image] => stdClass Object
  5. (
  6. [title] =>
  7. [url] => <a href="http://www.last.fm/music/Ewa+Farna/+images/57591921" target="_blank">http://www.last.fm/music/Ewa+Farna/+images/57591921</a>
  8. [dateadded] => Thu, 20 Jan 2011 15:56:58
  9. [format] => png
  10. [owner] => stdClass Object
  11. (
  12. [name] => maddie_XD
  13. [url] => <a href="http://www.last.fm/user/maddie_XD" target="_blank">http://www.last.fm/user/maddie_XD</a>
  14. [@attr] => stdClass Object
  15. (
  16. [type] => user
  17. )
  18.  
  19. )
  20.  
  21. [sizes] => stdClass Object
  22. (
  23. [size] => Array
  24. (
  25. [0] => stdClass Object
  26. (
  27. [#text] => <a href="http://userserve-ak.last.fm/serve/_/57591921/Ewa+Farna.png" target="_blank">http://userserve-ak.last.fm/serve/_/57591921/Ewa+Farna.png</a>
  28. [name] => original
  29. [width] => 248
  30. [height] => 371
  31. )
  32.  
  33. [1] => stdClass Object
  34. (
  35. [#text] => <a href="http://userserve-ak.last.fm/serve/126/57591921.png" target="_blank">http://userserve-ak.last.fm/serve/126/57591921.png</a>
  36. [name] => large
  37. [width] => 126
  38. [height] => 188
  39. )
  40.  
  41. [2] => stdClass Object
  42. (
  43. [#text] => <a href="http://userserve-ak.last.fm/serve/126s/57591921.png" target="_blank">http://userserve-ak.last.fm/serve/126s/57591921.png</a>
  44. [name] => largesquare
  45. [width] => 126
  46. [height] => 126
  47. )
  48.  
  49. [3] => stdClass Object
  50. (
  51. [#text] => <a href="http://userserve-ak.last.fm/serve/64/57591921.png" target="_blank">http://userserve-ak.last.fm/serve/64/57591921.png</a>
  52. [name] => medium
  53. [width] => 64
  54. [height] => 96
  55. )
  56.  
  57. [4] => stdClass Object
  58. (
  59. [#text] => <a href="http://userserve-ak.last.fm/serve/34/57591921.png" target="_blank">http://userserve-ak.last.fm/serve/34/57591921.png</a>
  60. [name] => small
  61. [width] => 34
  62. [height] => 51
  63. )
  64.  
  65. [5] => stdClass Object
  66. (
  67. [#text] => <a href="http://userserve-ak.last.fm/serve/252/57591921.png" target="_blank">http://userserve-ak.last.fm/serve/252/57591921.png</a>
  68. [name] => extralarge
  69. [width] => 252
  70. [height] => 377
  71. )
  72.  
  73. )
  74.  
  75. )
  76.  
  77. [votes] => stdClass Object
  78. (
  79. [thumbsup] => 38
  80. [thumbsdown] => 3
  81. )
  82.  
  83. )
  84.  
  85. [@attr] => stdClass Object
  86. (
  87. [artist] => Ewa Farna
  88. [page] => 1
  89. [perPage] => 1
  90. [totalPages] => 224
  91. [total] => 224
  92. )
  93.  
  94. )
  95.  
  96. )

teraz próbuje wyciągnąć
  1. $text = '#text';
  2. print $array[0]->images->image->sizes->size[0]->$text;


Za mało wiedzy mam biggrin.gif
W manualu tylko proste przykłady są
Go to the top of the page
+Quote Post
Ociu
post
Post #8





Grupa: Moderatorzy
Postów: 1 566
Pomógł: 37
Dołączył: 14.05.2003
Skąd: Kraków




Zobacz co Ci pokaże
  1. $array = json_decode($homepage, true);
  2. var_dump($array);
Go to the top of the page
+Quote Post
szczawik
post
Post #9





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 19.08.2010

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


otrzymałem:
  1. array(1) {
  2. ["images"]=>
  3. array(2) {
  4. ["image"]=>
  5. array(7) {
  6. ["title"]=>
  7. string(0) ""
  8. ["url"]=>
  9. string(51) "http://www.last.fm/music/Ewa+Farna/+images/57591921"
  10. ["dateadded"]=>
  11. string(25) "Thu, 20 Jan 2011 15:56:58"
  12. ["format"]=>
  13. string(3) "png"
  14. ["owner"]=>
  15. array(3) {
  16. ["name"]=>
  17. string(9) "maddie_XD"
  18. ["url"]=>
  19. string(33) "http://www.last.fm/user/maddie_XD"
  20. ["@attr"]=>
  21. array(1) {
  22. ["type"]=>
  23. string(4) "user"
  24. }
  25. }
  26. ["sizes"]=>
  27. array(1) {
  28. ["size"]=>
  29. array(6) {
  30. [0]=>
  31. array(4) {
  32. ["#text"]=>
  33. string(58) "http://userserve-ak.last.fm/serve/_/57591921/Ewa+Farna.png"
  34. ["name"]=>
  35. string(8) "original"
  36. ["width"]=>
  37. string(3) "248"
  38. ["height"]=>
  39. string(3) "371"
  40. }
  41. [1]=>
  42. array(4) {
  43. ["#text"]=>
  44. string(50) "http://userserve-ak.last.fm/serve/126/57591921.png"
  45. ["name"]=>
  46. string(5) "large"
  47. ["width"]=>
  48. string(3) "126"
  49. ["height"]=>
  50. string(3) "188"
  51. }
  52. [2]=>
  53. array(4) {
  54. ["#text"]=>
  55. string(51) "http://userserve-ak.last.fm/serve/126s/57591921.png"
  56. ["name"]=>
  57. string(11) "largesquare"
  58. ["width"]=>
  59. string(3) "126"
  60. ["height"]=>
  61. string(3) "126"
  62. }
  63. [3]=>
  64. array(4) {
  65. ["#text"]=>
  66. string(49) "http://userserve-ak.last.fm/serve/64/57591921.png"
  67. ["name"]=>
  68. string(6) "medium"
  69. ["width"]=>
  70. string(2) "64"
  71. ["height"]=>
  72. string(2) "96"
  73. }
  74. [4]=>
  75. array(4) {
  76. ["#text"]=>
  77. string(49) "http://userserve-ak.last.fm/serve/34/57591921.png"
  78. ["name"]=>
  79. string(5) "small"
  80. ["width"]=>
  81. string(2) "34"
  82. ["height"]=>
  83. string(2) "51"
  84. }
  85. [5]=>
  86. array(4) {
  87. ["#text"]=>
  88. string(50) "http://userserve-ak.last.fm/serve/252/57591921.png"
  89. ["name"]=>
  90. string(10) "extralarge"
  91. ["width"]=>
  92. string(3) "252"
  93. ["height"]=>
  94. string(3) "377"
  95. }
  96. }
  97. }
  98. ["votes"]=>
  99. array(2) {
  100. ["thumbsup"]=>
  101. string(2) "38"
  102. ["thumbsdown"]=>
  103. string(1) "3"
  104. }
  105. }
  106. ["@attr"]=>
  107. array(5) {
  108. ["artist"]=>
  109. string(9) "Ewa Farna"
  110. ["page"]=>
  111. string(1) "1"
  112. ["perPage"]=>
  113. string(1) "1"
  114. ["totalPages"]=>
  115. string(3) "224"
  116. ["total"]=>
  117. string(3) "224"
  118. }
  119. }
  120. }
Go to the top of the page
+Quote Post
Ociu
post
Post #10





Grupa: Moderatorzy
Postów: 1 566
Pomógł: 37
Dołączył: 14.05.2003
Skąd: Kraków




Zaczyna mi się kończyć cierpliwość.
To jest tablica asocjacyjna. To co robiłeś na podstawie obiektów zrób na podstawie tablic asocjacyjnych.
Go to the top of the page
+Quote Post
szczawik
post
Post #11





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 19.08.2010

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


do mnie trzeba mieć anielską biggrin.gif

dałem coś takiego
$tablica['sizes']['size'][0]['#text'];
i pusto ;/
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: 20.08.2025 - 08:32