$order_table,"html"=>$html);html是table表格html代码通过jsJScript codeeval(""/> $order_table,"html"=>$html);html是table表格html代码通过jsJScript codeeval("">
Home > Backend Development > PHP Tutorial > 为何json_encode()之后,数组里元素成空值

为何json_encode()之后,数组里元素成空值

WBOY
Release: 2016-06-13 10:36:07
Original
1031 people have browsed it

为什么json_encode()之后,数组里元素成空值?

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> $data           =   array("order_table" => $order_table,"html"=>$html);
Copy after login


html是table表格html代码
通过js
JScript code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->eval("(" + xmlHttp.responseText + ")");
Copy after login

之后,有时候html变量成空值,order_table却没有,

在php情况下:
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$data  =  json_decode($data);print_r($data );
Copy after login

html也是空值!

这是为什么呢????一下午没解决.....那位高手帮忙指点

------解决方案--------------------
js只能json序列化轻量型的数组,多维数组json转不了。
------解决方案--------------------
$data = array("order_table" => $order_table,"html"=>$html);
你的 $data 不过是一个 php 数组,$data = json_decode($data); 如何能得到结果?
------解决方案--------------------
会不会要先转utf-8?
------解决方案--------------------
多维数组也是可以转化的,你可以通过浏览器调试工具跟踪一下,看看你的这个请求发出去到底返回了什么。


------解决方案--------------------
PHP code
public function removeMenuItemAction(){        $request = $this->getRequest();        $layout = $this->_helper->layout();        $layout->disableLayout();        $this->_helper->viewRenderer->setNoRender(true);        $menuId = $request->getParam('menuId', null);        if( $menuId > 0 ){            $SQLTool = new MysqlTool();            $con = $SQLTool->getConnect();            if( $con ){                $sqlLineMenu = "select Id FROM menubar where Type=0";                $resultMenu = mysql_query($sqlLineMenu);                $rowMenubar = mysql_fetch_array($resultMenu,MYSQL_ASSOC);                $menubarId = $rowMenubar['Id'];                // remove his children                $this->callBackMenuitemDelete($menuId,$menubarId);                                $sqlLine = "DELETE FROM menuitem WHERE Id = " . $menuId;                mysql_query($sqlLine);                mysql_close($con);                echo json_encode(array('message'=>"删除成功"));            }                 }else{            echo json_encode(array('message'=>"删除失败"));        }    }<br><font color="#e78608">------解决方案--------------------</font><br>这个不是多维数组的问题吧<br><br>感觉是含有 GB2312 的中文的原因<br><br>用UTF8<br><br>试试把HTML全部用英文或者UTF8格式,看看输出什么<br><br>
Copy after login
PHP code
$data = array("order_table" => $order_table,"html" => iconv("GBK","UTF-8//IGNORE",$html));<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
PHP code
 $data           =   array("order_table" => $order_table,"html"=>$html);exit(json_encode($data));<br><font color="#e78608">------解决方案--------------------</font><br>这种情况,只能是你手误了... $html 真的有东西?<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template