无法从 PHP json_encode 转换或访问 JSON 对象
<?php
$f_array = array(); // ---- Custom Line 1
for ($i=0; $i < $interval; ++$i)
{
$t_date = date('Y-m-d', strtotime($k_date1 . "+ $i day"));
$f_array = array();
$f_query = mysql_query("select COUNT(j.job_id) as `job_count`
from jobs j
where j.job_posted_date
LIKE '%$t_date%' and j.job_status = 3");
if (mysql_num_rows($f_query) > 0)
{
$f_query_data = mysql_fetch_array($f_query);
$f_count = $f_query_data['job_count'];
$f_array = array_push($f_array, $f_count); // ---- Custom Line 2
// $f_array[] = $f_count; // ---- Custom Line 3
}
}
$j_array = json_encode($f_array);
?>
我只得到一个值,即1
在 Javascript 中,使用enabling
Custom Line 1
& Custom Line 2
。
当 ienabled
Custom Line 3
和禁用Custom Line 1
& Custom Line 2
。然后我得到像从数据库一样好的输出
<script>
var j_array = "<?php echo $j_array; ?>";
</script>
结果 1
<script>
var j_array = "1";
</script>
结果 2
<script>
var j_array = "["0","0","0","2","0","0","0","0","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","2","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","25","0","0","0","0","0","7","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","1","0","0","1","1","47","0","1","1","0","0","0","0","0","0","3","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]";
</script>
我在下面附上了一张图片..
现在我如何Result 2
按顺序Array
或任何其他方法访问。
我尝试在下面使用
<script>
alert(j_array);
</script>
<script>
alert(j_array.0); // as an Object mightbe .. or I dont have any idea on it, so experimenting ..
</script>
我需要什么或需要帮助
它没有给出任何结果,因为0
它integer
不是string
..如果它是一个Array
那么它也很棘手..有n
很多String 0
..所以我怎么能一个一个地打电话。或转换成 Javascript 数组。
注意:Result 2
是所需的输出,但它不在Array