Home >Backend Development >PHP Tutorial >php对象转换成Json的问题

php对象转换成Json的问题

WBOY
WBOYOriginal
2016-06-23 13:54:50726browse

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


回复讨论(解决方案)

问题自已经解决了 欢迎进来拿分

$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
Previous article:关于数组处理的问题,急Next article:字符串 替换