json_encode删除array_values键吗? [英] json_encode dropping array_values key?

查看:95
本文介绍了json_encode删除array_values键吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP,并且 json_encode()有问题。该过程将擦除由 array_values命令设置的初始键,如下所示。

I am working in PHP and have an issue with json_encode(). The process wipes the inital "key" that was set by the "array_values" command as shown below.

array(1) { 
    [0]=> array(5) { 
        ["ID"]=> string(4) "2679" [
        "PackageName"]=> "Update for Windows 8.1 for x64-based Systems (KB2965065)" 
        ["Description"]=> string(262) "Install this update to resolve issues in Windows." 
        ["KB"]=> string(7) "2965065" 
        ["Repo"]=> string(21) "Windows Update Server" 
}

$packages = array_values($this->control->fetchPackageTables($this->input->get("platform")));             

[
    {
        "ID":"2679",
        "PackageName":"Update for Windows 8.1 for x64-based Systems (KB2965065)",
        "Description":"Install this update to resolve issues in Windows.", 
        "KB":"2965065",
        "Repo":"Windows Update Server"
    }
]

我尝试遍历数组并设置数字,但是仍然被丢弃。有想法吗?

I have tried looping with a foreach through the array and setting a number but it still gets dropped. Any ideas?

谢谢!

推荐答案

JSON不支持关联

JSON / Javascript中的数组仅由编号索引组成。关联数组将转换为对象/属性。

Arrays in JSON / Javascript consist only of numbered indexes. Associative arrays will be converted to objects/properties.

没有任何东西掉落。 [] 表示一个数组。 {} 表示对象。数组中有对象。

There is nothing getting dropped. [ ] indicates an array. { } indicates an object. You have one object in the array.

这篇关于json_encode删除array_values键吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆