Home  >  Article  >  Backend Development  >  php对象转换成Json的有关问题

php对象转换成Json的有关问题

WBOY
WBOYOriginal
2016-06-13 11:53:18869browse

php对象转换成Json的问题

<br />用的CI框架,在model里面有一个team_model<br />$this->load->model('Team_model');<br />$team=new Team_model;<br />$team->Id=1;<br />$team->Code='001';<br />$team->Caption='aa';<br />$jsonstr=json_encode($team);//这样转换的不对。先转成数组在用json_encode也不对。<br />//json格式要是{“team”:{"Id":1,"Code":"001","Caption":"aa"}};<br />//不用model用数组可以实这个<br />如:<br />$team['Id']=1;<br />$team['Code']='001';<br />$team['Caption']='aa';<br />$arrteam['team']=$team;<br />$jsonstr=json_encode($arrteam);<br />这样是可以实现但是没有用到model,MVC的框架用不到model,呵呵。。。。这还叫MVC吗。这太奇怪了。 让我凌乱了<br />

------解决方案--------------------

------解决方案--------------------
$team是对象,直接json_encode当然不对。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn