解决中文的一种方法就是先将中文转换为另一种编码格式,然后再使用json_encode(),最后再用解码把json串进行解码。还有一种方式就在php新版本中得到了解决,在下面的代码为展示。

以下为代码示例

<?php
header("Content-type:text/html;charset=utf-8");
$arrayName = array('city' => '广东','goods'=>'cookies' );
$arr = json_encode($arrayName);
echo $arr."</br>";
var_dump(json_decode($arr));
echo "</br>";
echo urldecode(json_encode(ch_json($arrayName)))."</br>";
/*
需要php版本在5.4以上
echo json_encode($arrayName,JSON_UNESCAPED_UNICODE);
*/
function ch_json($arr){
if(is_array($arr)){
foreach ($arr as $key => $value) {
$arr[urlencode($key)] = ch_json($value);
}
}else{
return urlencode($arr);
}
return $arr;
}
?>

PS:这里再为大家推荐几款比较实用的json在线工具供大家参考使用:

在线JSON代码检验、检验、美化、格式化工具:
http://tools.jb51.net/code/json
JSON在线格式化工具:
http://tools.jb51.net/code/jsonformat
在线XML/JSON互相转换工具:
http://tools.jb51.net/code/xmljson
json代码在线格式化/美化/压缩/编辑/转换工具:
http://tools.jb51.net/code/jsoncodeformat
C语言风格/HTML/CSS/json代码格式化美化工具:
http://tools.jb51.net/code/ccode_html_css_json

json-encode()怎么进行解码呢?的更多相关文章

  1. Golang的Json encode/decode以及[]byte和string的转换

    使用了太长时间的python,对于强类型的Golang适应起来稍微有点费力,不过操作一次之后发现,只有这么严格的类型规定,才能让数据尽量减少在传输和解析过程中的错误.我尝试使用Golang创建了一个公 ...

  2. escape,encodeURI,encodeURIComponent, URLEncode, RawURLEncode, HTMLEntity, AddSlash, JSON Encode

    online tooling: http://www.the-art-of-web.com/javascript/escape/ input : {user:{id:59,innerhtml:&quo ...

  3. php和js中json的编码和解码

    php中 1)编码 $jsonStr = json_encode($array) 2)解码 $arr = json_decode($jsonStr) <?php echo json_encode ...

  4. Python语言中对于json数据的编解码——Usage of json a Python standard library

    一.概述 1.1 关于JSON数据格式 JSON (JavaScript Object Notation), specified by RFC 7159 (which obsoletes RFC 46 ...

  5. Python 2.7.9 Demo - JSON的编码、解码

    #coding=utf-8 #!/usr/bin/python import json; dict = {}; dict['name'] = 'nick'; dict['say'] = 'hello ...

  6. js 中编码(encode)和解码(decode)的三种方法

    js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent 下 ...

  7. 54.NSJSONSerialization类进行json解析(字符串“UTF-8解码”)

    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllo ...

  8. golang json 编码解码

    json 编码 package main import ( "encoding/json" "fmt" ) type Person struct { Name ...

  9. Python3中json的encode和decode

    在Python3中,将对象序列化为JSON对象,即对对象进行json encode编码,使用函数 json.dumps(obj, *, skipkeys=False, ensure_ascii=Tru ...

  10. 51. ExtJs4之Ext.util.JSON编码和解码JSON对象

    转自:https://blog.csdn.net/iteye_9439/article/details/82518158 1.decode() 该方法用于将符合JSON格式的String进行解码成为一 ...

随机推荐

  1. [BS-24] UIImageView的contentMode属性

    UIImageView的contentMode属性   所有的UIView都有个contentMode属性,UIImageView继承自UIView,我们在使用UIImageView时,经常要考虑这些 ...

  2. 10月26日 奥威Power-BI基于微软示例库(MSOLAP)快速制作管理驾驶舱 腾讯课堂开课啦

    本次课是基于olap数据源的案例实操课,以微软olap示例库Adventure Works为数据基础.        AdventureWorks示例数据库为一家虚拟公司的数据,公司背景为大型跨国生产 ...

  3. RouterOS 软路由开启SSH服务器

    RouterOS软路由可以支持多种服务,例如SSH.FTP.Telnet.www等等 图形介面操作 命令操作 [admin@MikroTik] > ip service print        ...

  4. python set add 导致问题 TypeError: unhashable type: 'list'

    问题复现 >>> a = set() >>> b = set() >>> b.add(1) >>> a.add(b) Trace ...

  5. 修改了系统自带头文件后,Xcode会报错

    1.Xcode自带头文件的路径 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Develo ...

  6. Hint

    select  /*+  first_rows(20)  */  *  from  t  where  id<20 --分页 select  /*+  all_rows  */  *  from ...

  7. 导出iPhone中安装的APP的iPA文件

    1.让iPhone连接电脑,打开iTunes,选择本电脑,然后点立即备份. 2.完成上一步的操作之后,选择应用,在iTunes中就会列出你从App Store中下载的应用,自己连接真机调试的应用是没有 ...

  8. js星级评分点击星级评论打分效果

    html代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  9. CALayer 图层

    // CALayer 图层属性,继承UIView都有该属性,可设置边框宽度.颜色.圆角.阴影等 UIImageView *imageView = [[UIImageView alloc]initWit ...

  10. MS SQL SERVER 锁研究记录

    首先创建一直数据表 ChenJi,有如下字段: ID, DanWeiID,  Name,  ChenJi CREATE TABLE [dbo].[ChenJi]( [ID] [int] NOT NUL ...