javascript - Getting null in json_decode -
i have text file has json on it. example below:
{'something' : 'ss'}
i trying read on php , convert array using json_decode
.
$temp = ''; $fh = fopen( '/quiz' . $testid . '.txt' ,'r'); while ($line = fgets($fh)) { $temp .= $line; } fclose($fh); $temp = str_replace("\n","",$temp); //to remove new line $temp = str_replace("\r","",$temp); $temp = json_decode($temp);
but im getting null
if don't json_decode
it.. can string.
i hope can me this.
thanks, e
you don't need parsing prior calling json_decode
$contents = file_get_contents('/quiz' . $testid . '.txt'); $temp = json_decode($contents);
if you're still getting null, json invalid, can use json_last_error diagnose it.
Comments
Post a Comment