php 中利用json_encode和json_decode传递包括特殊字符的数据
2024-10-18 01:37:05
</pre><span style="font-size:24px"></span><pre name="code" class="php">
json_decode
mixed json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] )
接受一个 JSON 格式的字符串而且把它转换为 PHP 变量
json_encode
string json_encode ( mixed $value [, int $options = 0 ] )
返回 value 值的 JSON 形式
比方interface_x 中须要获取interface_y 中传递的数据data,而data中含有特殊字符,就能够在interface_y中把这些特殊字符存入数组,然后json_encode成json
格式的字符串,传递给interface_x。在interface_x中进行json_decode。
$json2 = json_decode($json, true);
//echo "json2:";
//var_dump($json2);
interface_y中对包括特殊字符的字符串进行处理,存入数组。并进行json_encode:
$value = '~!@#$%^&*()_+-={}:";<>? /\123456789123';
$data = array("key" => $value);
$json = json_encode($data);
//echo "json:" . "\n";
//var_dump($json);
在interface_x中对传入的json数据,进行json_decode成数组。
參考:
http://php.net/manual/zh/function.json-decode.php
http://php.net/manual/zh/function.json-encode.php
最新文章
- 字典树+博弈 CF 455B A Lot of Games(接龙游戏)
- 简单的方向传感器SimpleOrientationSensor
- jsonp原理
- mysql 存储过程简介
- RabbitMQ的工作队列和路由
- 如果浏览器自动调用quirks模式打开的话
- 解决ionic在ios无法使用focus,ios focus失效的问题
- ajax readyState的五种状态详解
- requirejs学习博客址分享
- Mina学习之IoBuffer
- 武汉科技大学ACM:1006: 华科版C语言程序设计教程(第二版)例题4.17
- 使用 C# 编写简易 ASP.NET Web 服务器
- Android studio教程:[4]真机测试
- 数据库 基于索引的SQL语句优化之降龙十八掌(转)
- 进程间通信系列 之 命名管道FIFO及其应用实例
- ssh爆破(python脚本)
- 【NumberValidators】大陆身份证验证
- js获取今天是星期几
- Java跨平台的原理
- JS--dom对象:document object model文档对象模型