php 的json 数据里 有双引号 和回车符 传到都会错
<?php
$arr = array (
array (
'catid' => '4',
'catname' => '招聘信息',
'meta_title' => '招聘信息标题'
),
array (
'catid' => '55',
'catname' => 'php教程',
'meta_title' => 'php教程标题',
)
);
//这是数组转换为json
$jsonstr = json_encode($arr);
echo $jsonstr;
//结果
//[{"catid":"4","catname":"\u62db\u8058\u4fe1\u606f","meta_title":"\u62db\u8058\u4fe1\u606f\u6807\u9898"},
//{"catid":"55","catname":"php\u6559\u7a0b","meta_title":"php\u6559\u7a0b\u6807\u9898"}]
<?php
//在 php端
foreach ($_jj_company as $key=>$value) {
$_jj_company[$key]['companyName'] = urlencode(iconv('GB2312','UTF-8',$value['companyName']));
}
$jsonData = json_encode($_jj_company);
$this->tpl->set('jsonData', $jsonData);
?>
//在html端
var jsonData=<?=$jsonData?>;
取数据应该是 decodeURIComponent(row.companyName); 就取到公司名了