JSON returns strange problem with data format?

Source: Internet
Author: User
JSON data returned in a local environment using LARAVEL3 is normal
For example {"id": 1}

But the data returned after uploading the code to the development machine becomes
{"id": "1"}
is all the value plus double quotes, all become a string type, very strange, do not know is the server Apache setup problem or what?

Header head is already content-type Application/json; Charset=utf-8

Local environment PHP5.4 MySQL 5.6
Development machine Environment PHP5.3 MySQL 5.0

Currently tentative question is PHP5.3 link MySQL driver problem php from 5.3 can be native return MySQL field type,
http://stackoverflow.com/questions/1197005/how-to-get-numeric-types-from-mysql-using-pdo#answer-1197041

Now the problem is to install MYSQLND on Centos6.4, the PHP5.3, but the default package inside No, do not know how to install?
http://stackoverflow.com/questions/13159518/how-to-enable-mysqlnd-for-php

Reply content:

JSON data returned in a local environment using LARAVEL3 is normal
For example {"id": 1}

But the data returned after uploading the code to the development machine becomes
{"id": "1"}
is all the value plus double quotes, all become a string type, very strange, do not know is the server Apache setup problem or what?

Header head is already content-type Application/json; Charset=utf-8

Local environment PHP5.4 MySQL 5.6
Development machine Environment PHP5.3 MySQL 5.0

Currently tentative question is PHP5.3 link MySQL driver problem php from 5.3 can be native return MySQL field type,
http://stackoverflow.com/questions/1197005/how-to-get-numeric-types-from-mysql-using-pdo#answer-1197041

Now the problem is to install MYSQLND on Centos6.4, the PHP5.3, but the default package inside No, do not know how to install?
http://stackoverflow.com/questions/13159518/how-to-enable-mysqlnd-for-php

Should have nothing to do with Apache, is the problem of the program code, is not where to convert the number into a string?

Can you do the conversion to integer before the data is returned?

Self-answer, the current tentative is a mysql-driven thing, do not know if anyone has encountered it?

http://stackoverflow.com/questions/1197005/how-to-get-numeric-types-from-mysql-using-pdo#answer-1197041

Please post your PHP version, as well as the source of the parameters used when using Json_encode, because it is possible that your data source is a database, the type defined in the database is a string, and then in Json_encode, it becomes a string.

The PHP version I used was 5.4.23, and I did the Json_encode test directly with hard code:


  
    'caiknife',    'age'    => 18,    'height' => '175'];Zend_Debug::dump(json_encode($json));Zend_Debug::dump(Zend_Json::encode($json));

Output Result:

string '{"name":"caiknife","age":18,"height":"175"}' (length=43)string '{"name":"caiknife","age":18,"height":"175"}' (length=43)

Did you get the JSON object tostring when you returned?

  • Related Article

    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.