Home >Backend Development >PHP Tutorial >,JSON显示多余的东西

,JSON显示多余的东西

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:36:511050browse

$result=$menu->show_twoMenu(4);
$col_jobs = array();
$i=0;
while(@$row=mysqli_fetch_array($result)){
$col_jobs[$i] = $row;
$i++;
}
$col_jobs = json_encode($col_jobs);
echo '{"coljobs":'.$col_jobs.'}';
输出却是:
{
    "coljobs": [
        {
            "0": "5",
            "1": "清蒸桂鱼",
            "2": "4",
            "3": "abc.jpeg",
            "4": "124",
            "5": "100",
            "6": "例",
            "7": "80",
            "8": "999",
            "id": "5",
            "Name": "清蒸桂鱼",
            "ParentID": "4",
            "Image": "abc.jpeg",
            "Discount": "124",
            "Price": "100",
            "Unit": "例",
            "Sale": "80",
            "Stock": "999"
        }
    ]
}
为什么会有
            "0": "5",
            "1": "清蒸桂鱼",
            "2": "4",
            "3": "abc.jpeg",
            "4": "124",
            "5": "100",
            "6": "例",
            "7": "80",
            "8": "999",
我不想要,怎么办?


回复讨论(解决方案)

mysqli_fetch_array 返回的是下标数组和关联数组的混合体
按你的需要应使用 mysqli_fetch_assoc 只返回关联数组

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn