Home  >  Article  >  Backend Development  >  PHP中给AJAX传来的数据类型是JSON的一点困惑

PHP中给AJAX传来的数据类型是JSON的一点困惑

WBOY
WBOYOriginal
2016-06-13 12:11:101044browse

PHP中给AJAX传回的数据类型是JSON的一点困惑

本帖最后由 u013037779 于 2014-12-06 07:18:06 编辑 我就是关于json_encode()怎么用也用不好
例如这边是控制器里要传的JSON数据

我要是直接写json_encode($a);也不行
这边接收端到ROW这里老报错
我试过用WINDOW.ALERT();证明服务器已经把数据返回,可这些数据是一系列HTML代码也不知道哪里来的,而不是我想要的数据。

请教一下这样该怎么用JSON_encode()写;
另外如果是从数据库中传回来一个2维数组,又该怎么写?比如我从数据库里通过名字查询到了他的一些列值
我把这些值封装成2维数组怎么通过用json_encode转化,能否受累提供一下代码
------解决思路----------------------
从 row.city.length 这样的用法上看
你的 php 程序应该只输出 {"city":["天津","武汉","长沙","广州"]} 这样的内容,如果多了其他东西,则无法转换成 js 对象
$a = array("天津","武汉","长沙","广州");<br />echo json_encode(array('city' => $a));

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