PHP json_encode 将行返回为数组而不是对象
根据我的经验,当我对 mysql 表中的数据进行 json_encode 时,输出是一个对象,其中包含每一行作为对象。我想要做的是将每一行作为数组,如下例所示(不需要其中的列名称)。我怎样才能做到这一点?
{ "Data": [
["1","Internet Explorer 4.0","Win 95+","4","X","1"],
["2","Internet Explorer 5.0","Win 95+","5","C","2"],
["3","Internet Explorer 5.5","Win 95+","5.5","A","3"],
["4","Internet Explorer 6","Win 98+","6","A","4"],
] }
From my experience, when I json_encode data from a mysql table, the output is an object containing each row as an object within. What I want to do is to get each row as an array, like the example below (don't need the column names in there). How can I do that?
{ "Data": [
["1","Internet Explorer 4.0","Win 95+","4","X","1"],
["2","Internet Explorer 5.0","Win 95+","5","C","2"],
["3","Internet Explorer 5.5","Win 95+","5.5","A","3"],
["4","Internet Explorer 6","Win 98+","6","A","4"],
] }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
mysql_fetch_row
[docs] 获取每一行。这将获得一行作为数字数组,并且这些行也被编码为 JSON 数组:Use
mysql_fetch_row
[docs] to get each row. This will get a row as a numerical array and those are also encoded as JSON arrays:口译员未检查:
您可以通过简单的类型转换来更改变量的类型:
您也可以使用下一个函数: array mysql_fetch_array (resource $result [, int $result_type ] )
NOT CHECKED in interpreter:
You can change the type of variable by simple types convertion:
Also you can use next function: array mysql_fetch_array ( resource $result [, int $result_type ] )