Home  >  Article  >  Backend Development  >  The php array is converted through json_encode. The json format cannot be recognized in js.

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

不言
不言Original
2018-05-04 10:23:312220browse

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!

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