Home > Backend Development > PHP Tutorial > laravel - php中json_encode输出值不一样。

laravel - php中json_encode输出值不一样。

WBOY
Release: 2016-06-06 20:46:29
Original
1009 people have browsed it

用print_r打印出来的数组是这样的:

<code>Array
(
    [total] => 8
    [rows] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [email] => 379395979@qq.com
                    [activated] => 1
                    [username] => yuan
                    [created_at] => 2014-03-04 02:30:43
</code>
Copy after login
Copy after login

为什么使用json_encode输出之后其他的数据都好的,就只有activated这个字段会把1的变成true,0的变成false,有人遇到过这个情况吗?该怎么解决才能输出原始的值。。。
框架是laravel4

json值像这样:

<code>{"total":8,"rows":[{"id":1,"email":"379395979@qq.com","activated":true,"activated_at":null,"last_login":"2014-04-03 05:41:30","username":"yuan","created_at":"2014-03-04 02:30:43"}
</code>
Copy after login
Copy after login

回复内容:

用print_r打印出来的数组是这样的:

<code>Array
(
    [total] => 8
    [rows] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [email] => 379395979@qq.com
                    [activated] => 1
                    [username] => yuan
                    [created_at] => 2014-03-04 02:30:43
</code>
Copy after login
Copy after login

为什么使用json_encode输出之后其他的数据都好的,就只有activated这个字段会把1的变成true,0的变成false,有人遇到过这个情况吗?该怎么解决才能输出原始的值。。。
框架是laravel4

json值像这样:

<code>{"total":8,"rows":[{"id":1,"email":"379395979@qq.com","activated":true,"activated_at":null,"last_login":"2014-04-03 05:41:30","username":"yuan","created_at":"2014-03-04 02:30:43"}
</code>
Copy after login
Copy after login

使用 var_dump 查看数据源头的类型,LZ 打印结果不同,问题出在数据源,如果数据表没有问题,应该是从数据库获取数据出来的数据格式有问题。

json_encode没有改变bool的值
..
刚才理解错误了
测试了一下,没发现json_encode有改变...
Laravel源码也没找着转换的地方..

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template