PHP JSON_encode()的奇怪JSON输出
我正在使用PHP玩JSON。我正在使用json_encode函数来创建json。我得到了奇怪的JSON输出:PHP JSON_encode()的奇怪JSON输出,php,json,Php,Json,我正在使用PHP玩JSON。我正在使用json_encode函数来创建json。我得到了奇怪的JSON输出: [ { "0": "1", "1": "test", "2": "test", "ID": "1", "title": "test", "imageUrl": "test" }, { "0": "2", "1": "welcome",
[
{
"0": "1",
"1": "test",
"2": "test",
"ID": "1",
"title": "test",
"imageUrl": "test"
},
{
"0": "2",
"1": "welcome",
"2": "http://overkiller.pl/Smokopedia/Images/01.jpg",
"ID": "2",
"title": "welcome",
"imageUrl": "http://overkiller.pl/Smokopedia/Images/01.jpg"
}
]
为什么我会得到这种JSON,如何从中去除这些数字?
我的PHP代码:
mysql_fetch_数组包括数字索引键和列名索引键
将其更改为mysql\u fetch\u assoc,您将获得所需的最终结果
注意到,整个MySQL扩展被弃用,你应该考虑切换到PDO或mySQL。
< P>问题是你正在获取一个数组,它包括数值索引和字符串键。 更改为mysql_fetch_assocwhile ($row = mysql_fetch_ssoc($result))
旁注:mysql_*库已被弃用。考虑升级到现代API,如MySQLi或PDO。谢谢。我忘记了PHP中的那个函数。
while ($row = mysql_fetch_ssoc($result))