`

PHP JSON的转换

    博客分类:
  • PHP
 
阅读更多
http://www.dewen.org/q/1801
将array 转换成 stdclass 在 转换成json字符串

json_decode — 对 JSON 格式的字符串进行编码
json_encode — 对变量进行 JSON 编码
json_last_error — 返回最后发生的错误

数组中所有中文在json_encode之后都不见了或者出现\u2353等。
解决方法是用urlencode()函数处理以下,在json_encode之前,把所有数组内所有内容都用urlencode()处理一下,然用json_encode()转换成json字符串,最后再用urldecode()将编码过的中文转回来。


public function site() {
		
		$Site = new Model("site");
		$records = $Site->select();
		
		print_r("JSON=".json_encode(new arrayobject($records)));
		echo '<br>';
		print_r(new arrayobject(json_decode('{"id":"1","name":"d","title":"y","tel":"y","QQ":"y","email":"u","addr":"u","acc_count":null}')));
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics