json_encode和json_decode 之间转换
程序员文章站
2022-04-17 09:14:32
...
$query = $this->getPluginList(); //查询语句返回值
$ret_plugin_ls = array();
foreach ($query->result() as $row) { //对象存储
array_push($ret_plugin_ls, $row);
}
echo json_encode($ret_plugin_ls);
以对象形式存储的json_encode数据(数据来源在上面) 如下:
$json= '[{"id":"1","plugin_name":"\u4e2a\u63a8","plugin_describe":"\u4e2a\u63a8\u63cf\u8ff0","plugin_provider":"\u897f\u6865","plugin_version":"1.0","plugin_upload_date":"2013-08-12 10:52:26","plugin_detail":"0","plugin_expired":"0"},{"id":"2","plugin_name":"213231","plugin_describe":"12123132","plugin_provider":"2123321213","plugin_version":"2.0","plugin_upload_date":"2013-08-11 15:20:55","plugin_detail":"0","plugin_expired":"0"}]';
转换成数组:
$arrdata = json_decode($json);
foreach ($allplugins as $row)
{
echo $row->id;
echo $row->plugin_name;
}
打印:
1
个推
2
213231
$ret_plugin_ls = array();
foreach ($query->result() as $row) { //对象存储
array_push($ret_plugin_ls, $row);
}
echo json_encode($ret_plugin_ls);
以对象形式存储的json_encode数据(数据来源在上面) 如下:
$json= '[{"id":"1","plugin_name":"\u4e2a\u63a8","plugin_describe":"\u4e2a\u63a8\u63cf\u8ff0","plugin_provider":"\u897f\u6865","plugin_version":"1.0","plugin_upload_date":"2013-08-12 10:52:26","plugin_detail":"0","plugin_expired":"0"},{"id":"2","plugin_name":"213231","plugin_describe":"12123132","plugin_provider":"2123321213","plugin_version":"2.0","plugin_upload_date":"2013-08-11 15:20:55","plugin_detail":"0","plugin_expired":"0"}]';
转换成数组:
$arrdata = json_decode($json);
foreach ($allplugins as $row)
{
echo $row->id;
echo $row->plugin_name;
}
打印:
1
个推
2
213231
回复讨论(解决方案)
楼主想说什么呢...
本人才疏学浅敬请谅解。
1、以json格式传送的数据,接受端要转化(json_decode)一下;
2、以对象格式存储发送,接收端也只能以对象格式输出显示。
楼主想说什么呢...
他在授业,不是请求解惑
上一篇: 利用PHP函数计算中英文字符串长度
推荐阅读
-
解决无法在unicode和非unicode字符串数据类型之间转换的方法详解
-
浅析php中json_encode()和json_decode()
-
c#实现16进制和字符串之间转换的代码
-
Python datetime和unix时间戳之间相互转换的讲解
-
Python3中内置类型bytes和str用法及byte和string之间各种编码转换 问题
-
python时间和时间戳之间的转换
-
C#中Byte[]和String之间转换的方法
-
JS实现unicode和UTF-8之间的互相转换互转
-
cdr美术字和段落文本之间怎么直接转换?
-
无法确定条件表达式的类型,因为“
”和“System.DateTime”之间没有隐式转换----解决办法