The php array is converted through json_encode. The json format cannot be recognized in js.

不言
Release: 2023-03-25 11:10:01
Original
2220 people have browsed it

This article mainly introduces the json format that cannot be recognized in js after being converted by json_encode. It has a certain reference value. Now I share it with you. Friends in need can refer to it

First of all, let me explain one point. The json format in js uses curly brackets '{}', starting and ending with one character.

But in php, the array with # as the index, after json_encode conversion, is an array with square brackets ' []', a string starting and ending. Therefore, JSON.parse cannot be used to convert data in js.

In order to solve this problem, I thought of many ways, but it felt inconvenient no matter what I did. Finally, I found a relatively simple way.


########### There is also a problem, that is, the array with the default index cannot be used, but this problem is not big. At present, this method is relatively simple############Related recommendations:#########Functions for converting PHP arrays and XML to each other######

The above is the detailed content of The php array is converted through json_encode. The json format cannot be recognized in js.. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!