Help, please, display text from json file:

var_dump($news); string(188994) "{ "Новости":{ "Новость":{ "Категория":"Первая", "Дата":"Сегодня" } } 

How do I print text from each array like this? echo $news['Категория'];

  • And where is your array here? - Chad
  • Start by decoding the string into an array. - u_mulder
  • Can you tell me how to do this? - user188252
  • Cyrillic evil, especially as key - Vfvtnjd
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

Like this:

 $news = json_decode($news); echo $news["Новости"]["Новость"]["Категория"]; 
  • Thanks, it works, but how to get all the $ news ["News"] ["News"] ["Category"]? - user188252
  • I deduce foreach ($ news as $ new) {print_r ($ new);} Such feeling that after json_decode (), only the first element gets to an array. - user188252
  • in order for the output of json_decode be an associative array, you need to pass the second argument to the function: json_decode($news, true) - Dmitriy Simushev
  • So I did, but only one news falls into the array: Array ([News] => Array ([News] => Array ([Category] => First [Date] => Today))) - user188252
  • @ user188252 What did you really want? Новости is an object and not an array. - Dmitriy Simushev