本周开始用PHP编程,所以这里总的初学者。 下面的代码示例不完整,但它可以让您了解问题。 如果我在我的类中只保留了2个属性,我能够转换并显示我的数组中的JSON结构,但是当我在类中添加更多属性时,没有返回/显示/转换。这是为什么?谢谢 NOte:我尝试了http://php.net/manual/en/json.constants.php
中的一些选项<?php
class myObject
{
public $Channel;
public $Program;
public $Episode;
public $Start;
public $End;
public $TZ;
}
$myBlackouts = array();
$row = 1;
if (($handle = fopen($file_name, 'r')) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ',')) !== FALSE)
{
//feed variables here
$myBlackout = new myObject;
$myBlackout->Channel = $Channel;
$myBlackout->Program = $Program;
$myBlackout->Episode = $Episode;
$myBlackout->Start = $StartEpoch;
$myBlackout->End = $EndEpoch;
$myBlackout->TZ = $TZ;
$myBlackouts[] = $myBlackout;
$row++;
}
fclose($handle);
}
echo 'Array lenght: '.count($myBlackouts)."\n"; //331 elements inside array
$myJSON = json_encode($myBlackouts); //convert array to JSON
echo $myJSON; // it will not display anything if I increase the number of properties in my class above
?>
由于
答案 0 :(得分:0)
iconv('UTF-8','UTF-8 // IGNORE',utf8_encode($ input));是我案子的解决方案。