php 对象数组转json字符串5
来源:互联网 发布:菱王电梯怎么样知乎 编辑:程序博客网 时间:2024/05/27 00:33
- <?php
- header("content-type:text/html; charset=utf-8");
- class Student {
- private $number;
- private $name;
- private $score;
- function __construct($number,$name,$score){
- $this->number=$number;
- $this->name=$name;
- $this->score=$score;
- }
- public function getNumber() {
- return $this->number;
- }
- public function getName() {
- return $this->name;
- }
- public function getScore() {
- return $this->score;
- }
- public function setNumber($number) {
- $this->number = $number;
- }
- public function setName($name) {
- $this->name = $name;
- }
- public function setScore($score) {
- $this->score = $score;
- }
- }
- $student1 = new Student("01","汤姆",80);
- $student2 = new Student("02","杰瑞",85);
- $arr =array();
- array_push($arr, $student1);
- array_push($arr, $student2);
- print_r($arr);
- $json_string = json_encode($arr,JSON_UNESCAPED_UNICODE);
- echo $json_string;
- ?>
- 结果为
- X-Powered-By: PHP/5.5.7
- Set-Cookie: ZendDebuggerCookie=127.0.0.1%3A10137%3A0||084|77742D65|1020; path=/
- content-type:text/html; charset=utf-8
- Array
- (
- [0] => Student Object
- (
- [number:Student:private] => 01
- [name:Student:private] => 汤姆
- [score:Student:private] => 80
- )
- [1] => Student Object
- (
- [number:Student:private] => 02
- [name:Student:private] => 杰瑞
- [score:Student:private] => 85
- )
- )
- [{},{}]
按官方的说法,私有变量无法被序列化出来
但是我并没有直接访问私有变量啊
如想得到以下结果,该怎么做?
0 0
- php 对象数组转json字符串5
- json字符串转json对象或者数组
- js 字符串转json数组对象
- java字符串及数组转json对象
- JSon对象、JSon数组和JSon字符串。
- JSON字符串,JSON对象,JSON数组
- JS中json字符串和json对象之间的转换,PHP中json字符串和php数组之间的转换
- SpringMVC Json字符串/Json字符串数组转对象/对象数组方法
- Json字符串/Json字符串数组转对象/对象数组方法-----II
- js解析json数组+java对象转json字符串
- json对象转化字符串、数组
- json值、json对象、json数组、json字符串区别
- json 数组 转json对象。
- Json对象转json数组
- json字符串转json对象
- JSON字符串转JSON对象
- json字符串转json对象
- json 字符串转json 对象
- 蓄水池问题
- Android入门开发之常用的adb指令以及AndroidStudio基本配置(五)
- doc命令下的复制粘贴
- 面向对象和基于对象
- 【分治法】最接近点对问题
- php 对象数组转json字符串5
- 右左法则——复杂指针解析
- cadence 的元件库介绍
- 一个web页面的访问的过程
- Bootstrap基础练习(一)
- Maven的依赖关系
- 关于今天参观了世界机器人大会的一些感想
- 微信公众号点击菜单 无法提供服务
- NOIP2016初赛记