PHP json_decode($json, TRUE) TRUE使数据格式化为Array,而非object
2013-04-12 17:19
453 查看
PHP使用json_encode处理后为非标准json, 使用json_decode($json) 解析后会变成object类型
json_decode()有第二个参数可以来处理,设置第二个参数为TRUE json_decode($json, TRUE)
json_decode()有第二个参数可以来处理,设置第二个参数为TRUE json_decode($json, TRUE)
$array = array('name'=>'sean', 'age'=>12); $j_arr = json_encode($array); $j_arrs = json_decode($j_arr);//json_decode($json, TRUE)没有设置第二个参数时 echo '<pre>'; var_dump($j_arrs); echo '</pre>'; 结果为对象 object(stdClass)#1 (2) { ["name"]=> string(4) "sean" ["age"]=> int(12) }
//设置json_decode() 第二个参数TRUE返回标准格式数据 $j_arrs = json_decode($j_arr, TRUE); //设置为TRUE返回数组 array(2) { ["name"]=> string(4) "sean" ["age"]=> int(12) }
相关文章推荐
- 调用短信接口,先var_dump()看数据类型是object需要json_decode(json_encode( $resp),true)转换成array
- PHP“Cannot use object of type stdClass as array” (php在调用json_decode从字符串对象生成json对象时的报错)
- JSONObject与JSONArray的区别 解析json数据
- php JSON数据格式化方法
- json_decode(Cannot use object of type stdClass as array)
- PHP自定义函数格式化json数据示例
- php JSON数据格式化方法
- PHP中 json_decode 转化 为 array 及 stdclass object
- JSONArray ja = JSONArray.fromObject(list);//特殊类 用于将list转化为JSON 数据并返回 out.print(ja);
- php 中利用json_encode和json_decode传递包含特殊字符的数据
- 对象转JSONArray,JSONObject[包括对象中日期格式化,属性过滤]
- JSON数据解析(JSONArray和JSONObject)
- 如何用String字符串生成JSONObject和JSONArray数据
- php中json_decode()和json_encode()的使用方法以及其参数‘true’
- android 读取json数据(遍历JSONObject和JSONArray)
- PHP自定义函数格式化json数据示例
- PHP JSON出错:Cannot use object of type stdClass as array解决方法
- PHP的serialize序列化数据以及JSON格式化数据分析
- php json_encode数据格式化
- 用JSONObject和JSONArray 解析json数据