Home  >  Article  >  Backend Development  >  PHP interface json data problem

PHP interface json data problem

WBOY
WBOYOriginal
2016-08-18 09:15:381074browse

After I query or update the data in the interface, I need to return the data in json format. The problem now is that after processing the returned data through json_encode, some int type data also has quotation marks. I want to put single quotation marks in the int type field value. Remove how to set it, do you need to use regular replacement processing? Solve

Reply content:

After I query or update the data in the interface, I need to return the data in json format. The problem now is that after processing the returned data through json_encode, some int type data also has quotation marks. I want to put single quotation marks in the int type field value. Remove how to set it, do you need to use regular replacement processing? Solve

Also use regular expressions! It's not that troublesome. Can't you just add a parameter directly? JSON_NUMERIC_CHECK can convert the int type in the array very user-friendly. I definitely didn't read the manual carefully. Reference is as follows

<code>// $array 你要返回的数组
exit(json_encode((array)($array), JSON_NUMERIC_CHECK));</code>

Just set the JSON_NUMERIC_CHECKparameter

Since PHP is a weakly typed language
Manually traverse formatting

intval
floatval
boolval
strval

Mainly use these functions

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:Can't access localhost?Next article:Can't access localhost?