PHP interface json data problem

WBOY
Release: 2016-08-18 09:15:38
Original
1094 people have browsed it

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>
Copy after login

Just set the JSON_NUMERIC_CHECKparameter

Since PHP is a weakly typed language
Manually traverse formatting

intval
floatval
boolval
strval

Mainly use these functions

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