Php object conversion to Json

Source: Internet
Author: User
Php object conversion to Json
In the CI framework used, there is a team_model $ this-> load-> model ('Team _ Model') in the model; $ Team = new Team_model; $ team-> Id = 1; $ team-> Code = '001'; $ team-> Caption = 'a'; $ jsonstr = json_encode ($ team ); // The conversion is incorrect. It is not correct if json_encode is used to convert the data to an array first. // Json format: {"team": {"Id": 1, "Code": "001", "Caption": "aa "}}; // you can use arrays without using the model, for example, $ team ['id'] = 1; $ team ['code'] = '001 '; $ team ['Caption '] = 'a'; $ arrteam ['team'] = $ team; $ jsonstr = json_encode ($ arrteam ); in this way, model can be implemented but model is not used. the MVC framework cannot use model .... Is it also called MVC. This is so strange. Make me messy


Reply to discussion (solution)

The problem has been solved. please come in and take the score.

$ Team is an object. json_encode is incorrect.

How can I deal with this problem?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.