PHP数组对象与Json转换操作实例分析(2)


输出对象属性
string(9) "李小龙"
-------------------------------
对象转数组
array(3) { ["name"]=> string(9) "李小龙" ["tel"]=> string(11) "11111111111" ["age"]=> string(2) "12" }
输出数组数值
string(9) "李小龙"
-------------------------------
Json到数组
array(8) { ["a"]=> string(6) "哈哈" ["b"]=> string(3) "我" ["c"]=> string(3) "数" ["d"]=> string(3) "一" ["e"]=> string(1) "3" ["f"]=> string(1) "2" ["g"]=> string(1) "1" ["h"]=> string(12) "别生气了" }
官方换种方法
对象
object(stdClass)#2 (8) { ["a"]=> string(6) "哈哈" ["b"]=> string(3) "我" ["c"]=> string(3) "数" ["d"]=> string(3) "一" ["e"]=> int(3) ["f"]=> int(2) ["g"]=> int(1) ["h"]=> string(12) "别生气了" }
属性:哈哈
数组
array(8) { ["a"]=> string(6) "哈哈" ["b"]=> string(3) "我" ["c"]=> string(3) "数" ["d"]=> string(3) "一" ["e"]=> int(3) ["f"]=> int(2) ["g"]=> int(1) ["h"]=> string(12) "别生气了" }
-------------------------------
数组到Json
array(8) { ["a"]=> string(6) "哈哈" ["b"]=> string(3) "我" ["c"]=> string(3) "数" ["d"]=> string(3) "一" ["e"]=> string(1) "3" ["f"]=> string(1) "2" ["g"]=> string(1) "1" ["h"]=> string(12) "别生气了" }
string(136) ""{\"a\":\"\u54c8\u54c8\",\"b\":\"\u6211\",\"c\":\"\u6570\",\"d\":\"\u4e00\",\"e\":3,\"f\":2,\"g\":1,\"h\":\"\u522b\u751f\u6c14\u4e86\"}""

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

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP中json格式数据操作技巧汇总》、《PHP数学运算技巧总结》、《PHP基本语法入门教程》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/3830.html