I can't get the remote json output with php.

topic description

I want to get information through the json of the website. I don"t know why I can"t get it. It"s normal that the json URL has been tested. Do you guys help me to study the code to see what"s wrong?

sources of topics and their own ideas

it seems normal to get data, and I feel that the problem appears in $timeline=json_decode ($timeline,true); here, alas

related codes

<?php
function get_file_content($url,$fgc=false){
  $file_contents="";
  if($fgc&&function_exists("file_get_contents")){
    $file_contents=@file_get_contents($url);
  }
  if(empty($file_contents)){
    $ch=curl_init();
    $timeout=5;
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
    $file_contents=curl_exec($ch);
    curl_close($ch);
  }
  return $file_contents;
}

$timeline=get_file_content("json");
$timeline=json_decode($timeline,true);
if($timeline){
  $title=$timeline["posts"][0]["title"];
  echo $title;
}else{
  echo(0);
}
?>


Nov.19,2021

what's wrong with it? it's the wrong json format.


first output the string you got directly. Make sure it's all right. Another is whether the coding is correct. Json can only support utf8.
you can call json_last_error_msg, after json_decode to get the last error message


use error_log to see if the output is correct.


print $timeline, first. Json, calls json_last_error () after json decode to see if there is a parsing error.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30eb4-2bd4d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30eb4-2bd4d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?