解决中文的一种方法就是先将中文转换为另一种编码格式,然后再使用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. 学习JAVA 安装

    下载 JDK      Tomcat9     Apache     mod_jk 1.安装JDK 这里就说配置环境变量 添加环境变量 JAVA_HOME(就是jdk的安装路径) CLASSPATH( ...

  2. 前端实战——照片墙gallery的实现

    对应的html代码 <!doctype html> <html lang="zh-hans"> <head> <meta charset= ...

  3. iOS 瀑布流的Demo

    /** * 瀑布流Demo的主要代码,若想看完整的代码请到下面链接去下载 * * 链接: https://pan.baidu.com/s/1slByAHB 密码: r3q6 */ #import &l ...

  4. ios理解 -- Pro Mutlithreading and Memory Management for iOS and OS X with ARC, Grand Central Dispatch, and Blocks

    Capturing automatic variables Next, you need to learn what the “together with automatic (local) vari ...

  5. DTMF Stresstesting

    import threading,time,serial,sys from random import randrange   port_snd=14 port_recv=2 recnt=0 ser_ ...

  6. mysql:on duplicate key update与replace into

    在往表里面插入数据的时候,经常需要:a.先判断数据是否存在于库里面:b.不存在则插入:c.存在则更新 一.replace into 前提:数据库里面必须有主键或唯一索引,不然replace into ...

  7. mysql:键缓存

    myisam的主要优化参数: key_buffer_size - 这对MyISAM表来说非常重要,是用来设置整个MySQL中常规Key Cache的大小.一般来说,如果MySQL运行在32位平台,此值 ...

  8. 在navgationController中添加UISegmentedControl

    NSArray *segmentedArray = [NSArray arrayWithObjects:@"患者基本信息",@"患者信息",nil]; UISe ...

  9. respondsToSelector: selector

    -(BOOL) respondsToSelector: selector 用来判断是否有以某个名字命名的方法(被封装在一个selector的对象里传递)

  10. win7旗舰版梦幻主题补丁~完美你的桌面

    随着VISTA和WIN7的逐渐普及,你是否想拥有一个与众不同的动态桌面呢~ Windows DreamScene属于Ultimate Extras的组件之一,而Ultimate Extras是专门为W ...