Home > Backend Development > PHP Tutorial > JSON 中文UNICODE编码问题,请指点

JSON 中文UNICODE编码问题,请指点

WBOY
Release: 2016-06-23 13:51:16
Original
1136 people have browsed it

http://bbs.csdn.net/topics/390858302
例如现在我有一串 {"a":"\u4e2d\u6587\u540d\u79f0","b":"\u6d4b\u8bd5\u7a0b\u5e8f\u3002"} 
我要用js,如何读取它的中文信息?
我要用php,如何读取它的中文信息?
请各位大牛指点迷津。谢谢。


回复讨论(解决方案)

$content = '{"a":"\u4e2d\u6587\u540d\u79f0","b":"\u6d4b\u8bd5\u7a0b\u5e8f\u3002"}';$json = json_decode($content, true);echo '<meta http-equiv="content-type" content="text/html;charset=utf-8">';echo $json['a'].'<br>'; //中文名称echo $json['b'];        // 测试程序。
Copy after login


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <meta http-equiv="content-type" content="text/html; charset=utf-8">  <title> New Document </title> </head> <body>  <script type="text/javascript">  var content = {"a":"\u4e2d\u6587\u540d\u79f0","b":"\u6d4b\u8bd5\u7a0b\u5e8f\u3002"};  document.write('a:' + content.a + ' ' + 'b:' + content.b); //a:中文名称 b:测试程序。  </script> </body></html>
Copy after login

作为 js 代码

o = {"a":"\u4e2d\u6587\u540d\u79f0","b":"\u6d4b\u8bd5\u7a0b\u5e8f\u3002"};alert(o.a) 
Copy after login
作为 js 字符串
s = '{"a":"\u4e2d\u6587\u540d\u79f0","b":"\u6d4b\u8bd5\u7a0b\u5e8f\u3002"}';o = eval(s);alert(o.a) 
Copy after login
按 php 对象访问
$s = '{"a":"\u4e2d\u6587\u540d\u79f0","b":"\u6d4b\u8bd5\u7a0b\u5e8f\u3002"} ';$o = json_decode($s);echo $o->a;
Copy after login
按 php 数组访问
$s = '{"a":"\u4e2d\u6587\u540d\u79f0","b":"\u6d4b\u8bd5\u7a0b\u5e8f\u3002"} ';$a = json_decode($s, true);echo $a['a'];
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