Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][JSON], Problem z dekodowaniem
mishka49
post
Post #1





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 15.07.2013

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


Witam. Na początek chcę zaznaczyć że raczkuję w php.
Mam problem z dekodowaniem JSON, api od reducelnk zwraca takie coś
  1. Resource id #21{"error":0,"msg":"None","link":"http:\/\/lnk.co\/KXOO1"}

  1. echo $rdl->{'link'};

Nie wydobywa linku. Mogę prosić o pomoc?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 11)
Turson
post
Post #2





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


json_decode()
Go to the top of the page
+Quote Post
mishka49
post
Post #3





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 15.07.2013

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


Całość wygląda tak
  1. $rdl = json_decode(file_get_contents('https://reducelnk.com/api.php?task=shorten&user=LOGIN&pass=HASŁO&url=http://google.pl/));
  2. echo $rdl->{'link'};

i zwraca taki błąd
  1. Notice: Trying to get property of non-object in
Go to the top of the page
+Quote Post
Turson
post
Post #4





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Zobacz kolorowanie składni. Nie domknąłeś czegoś
Go to the top of the page
+Quote Post
mishka49
post
Post #5





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 15.07.2013

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


Składnia jest w porządku
Go to the top of the page
+Quote Post
Turson
post
Post #6





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


  1. $rdl = json_decode(file_get_contents('https://reducelnk.com/api.php?task=shorten&user=LOGIN&pass=HASŁO&url=http://google.pl/));
  2. echo $rdl->{'link'};

  1. $rdl = json_decode(file_get_contents('https://reducelnk.com/api.php?task=shorten&user=LOGIN&pass=HASŁO&url=http://google.pl/'));
  2. echo $rdl->{'link'};

widzisz różnicę?

daj teraz
  1. print_r($rdl);

i przekonaj sie jak wyglada tablica

Ten post edytował Turson 26.01.2014, 12:56:49
Go to the top of the page
+Quote Post
mishka49
post
Post #7





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 15.07.2013

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


Ciągle ten błąd
  1. Notice: Trying to get property of non-object in
Go to the top of the page
+Quote Post
Turson
post
Post #8





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Której linii to się tyczy
Go to the top of the page
+Quote Post
mishka49
post
Post #9





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 15.07.2013

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


Tak wygląda cały kod
  1. <?
  2. $rdl = json_decode(file_get_contents('https://reducelnk.com/api.php?task=shorten&user=XXX&pass=XXX&url=http://google.pl'));
  3. echo $rdl->{'link'};
  4. ?>

a błąd dot. 3 lini tego echo
Go to the top of the page
+Quote Post
Turson
post
Post #10





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


mówiłem, żebyś dał print_r($rdl) ale nie słuchasz
nie $rdl->{'link'} a $rdl['element tablicy']
Go to the top of the page
+Quote Post
mishka49
post
Post #11





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 15.07.2013

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


Dziwne, tablica jest pusta, lepiej, nie wyświetla się nawet "Array()"
Go to the top of the page
+Quote Post
Turson
post
Post #12





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Nie wiem czy zauważyłeś ale file_get_contents() z tego linku wywala błędy. Chyba musisz curlem pobrać źródło
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 23.08.2025 - 01:01