热搜:NVER node 开发 php

json_encode和json_decode 之间转换

2024-09-21 18:50:02
json_encode和json_decode 之间转换

$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


回复讨论(解决方案)

楼主想说什么呢...

本人才疏学浅敬请谅解。
1、以json格式传送的数据,接受端要转化(json_decode)一下;
2、以对象格式存储发送,接收端也只能以对象格式输出显示。

楼主想说什么呢...
他在授业,不是请求解惑