【问题标题】:Why json_decode is not working?为什么 json_decode 不起作用?
【发布时间】:2016-05-31 09:00:36
【问题描述】:

我正在尝试读取和 json_decode 一个包含一些 json_encoded 元素的文件。我的 php 文件正在读取编码的元素,但没有将其解码为数组。有什么问题?

<?php 
$filename1 ="history.txt";
$filecontent=file_get_contents($filename1);
$history=Array();
$history=json_decode($fileContent,true);
$ar_size=sizeof($history);
echo $filecontent;
echo $ar_size;
?>

第一个回显给出 file1 的文件内容,但第二个回显给出 0。我的 history.txt 包含:

[" 1 2 3 4 5 6 7 8 9 10 11 &2.829476 "," 1 2 4 3 5 6 7 8 9 10 11 &2.782541 "]

【问题讨论】:

  • 好的,已编辑.. 仍未修复

标签: php arrays json file


【解决方案1】:

这是一个错字。

$history=json_decode($fileContent,true);
$history=json_decode($filecontent,true);

【讨论】:

  • 没问题。一个好的 IDE 会告诉您此类错误。和 php 也一样: 注意:未定义的变量:C:\...\..php 中的 fileContent 在第 13 行
猜你喜欢
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 2013-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多