json返回数据格式的奇怪问题?
在本地的环境中 使用laravel3 返回的json数据都是正常的
例如{"id":1}
但把代码传到开发机后 返回的数据变成了
{"id":"1"}
就是所有的值全加上了双引号, 全变成了字符串类型, 非常奇怪,不知道是服务器apache的设置问题还是什么?
header 头部 已经是 Content-Type application/json; charset=UTF-8
本地环境 PHP5.4 mysql 5.6
开发机环境 PHP5.3 mysql 5.0
目前暂定问题 是 PHP5.3的链接mysql驱动问题 PHP从5.3开始才可以原生返回mysql字段类型,
http://stackoverflow.com/questions/1197005/how-to-get-numeric-types-from-mysql-using-pdo#answer-1197041
现在的问题是要安装 mysqlnd 在Centos6.4, 的PHP5.3上, 但默认包里面没有,不知道如何安装?
http://stackoverflow.com/questions/13159518/how-to-enable-mysqlnd-for-php
回复内容:
在本地的环境中 使用laravel3 返回的json数据都是正常的
例如{"id":1}
但把代码传到开发机后 返回的数据变成了
{"id":"1"}
就是所有的值全加上了双引号, 全变成了字符串类型, 非常奇怪,不知道是服务器apache的设置问题还是什么?
header 头部 已经是 Content-Type application/json; charset=UTF-8
本地环境 PHP5.4 mysql 5.6
开发机环境 PHP5.3 mysql 5.0
目前暂定问题 是 PHP5.3的链接mysql驱动问题 PHP从5.3开始才可以原生返回mysql字段类型,
http://stackoverflow.com/questions/1197005/how-to-get-numeric-types-from-mysql-using-pdo#answer-1197041
现在的问题是要安装 mysqlnd 在Centos6.4, 的PHP5.3上, 但默认包里面没有,不知道如何安装?
http://stackoverflow.com/questions/13159518/how-to-enable-mysqlnd-for-php
应该跟 apache 无关,是程序代码的问题吧,是不是在哪里把数字转换成字符串了?
可以在数据返回前再做下转换成整型的操作么
自问自答,目前暂定为是Mysql驱动的事情 , 不知道有人遇到过吗?
http://stackoverflow.com/questions/1197005/how-to-get-numeric-types-from-mysql-using-pdo#answer-1197041
请贴出你的 PHP 版本,以及使用到 json_encode 时,所用参数的来源,因为很有可能你的数据来源是数据库的时候,数据库里定义的类型是字符串,于是在 json_encode 的时候,就变成了字符串。
我用的 PHP 版本是 5.4.23,直接用硬编码做了 json_encode 的测试:
<?php require_once 'zend_autoload.php'; $json = [ 'name' => 'caiknife', 'age' => 18, 'height' => '175' ]; Zend_Debug::dump(json_encode($json)); Zend_Debug::dump(Zend_Json::encode($json));
输出结果:
<code>string '{"name":"caiknife","age":18,"height":"175"}' (length=43) string '{"name":"caiknife","age":18,"height":"175"}' (length=43) </code>
你是在返回的时候将JSON对象toString了么?

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

The main functions of ApacheHTTPServer include modular design, virtual host configuration and performance optimization. 1. Modular design implements functions by loading different modules, such as SSL encryption and URL rewriting. 2. Virtual host configuration allows multiple websites to be run on one server. 3. Performance optimization improves performance by adjusting parameters such as ServerLimit and KeepAlive.

HTML5 brings five key improvements: 1. Semantic tags improve code clarity and SEO effects; 2. Multimedia support simplifies video and audio embedding; 3. Form enhancement simplifies verification; 4. Offline and local storage improves user experience; 5. Canvas and graphics functions enhance the visualization of web pages.

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

Apache is an open source web server software that is widely used in website hosting. Installation steps: 1. Install using the command line on Ubuntu; 2. The configuration file is located in /etc/apache2/apache2.conf or /etc/httpd/conf/httpd.conf. Through module extensions, Apache supports static and dynamic content hosting, optimizes performance and security.
