I want to convert an array into json
The array is output in this way.
Print_r ($ arrary); // output result: array ([0] => upload/2013/05/09/14303 .jpeg [1] => upload/2013/05/09/14300 .jpeg [2] => upload/2013/05/09/148 .jpeg [3] => upload/2013/05/09/187 .jpeg [4] => upload/2013/05/09/14296 .jpeg [5] => upload/2013/05/09/203 .jpeg) $ jarr = json_encode ($ arrary); // Convert the array to jsonprint_r ($ jarr); // output the result: ["upload \/2013 \/05 \/09 \/14303.jpeg", "upload \/2013 \/05 \/09 \/14300.jpeg ", "upload \/2013 \/05 \/09 \/148.jpeg", "upload \/2013 \/05 \/09 \/187.jpeg ", "upload \/2013 \/05 \/09 \/14296.jpeg", "upload \/2013 \/05 \/09 \/203.jpeg"]
Why is there no key for json? Shouldn't it be "0": upload/2013/05/09/14303 .jpeg? In addition, there are many more "\" originally only "/" URLs stored in the original array. what is the problem?
Reply to discussion (solution)
The json data format is like this, and there is no problem with calling in js.
The json data format is like this, and there is no problem with calling in js.
But I don't think the tutorials on the Internet are all "0": upload/2013/05/09/14303 .jpeg? What is the reason for this?
The json data format is like this, and there is no problem with calling in js.
But I don't think the tutorials on the Internet are all "0": upload/2013/05/09/14303 .jpeg? What is the reason for this?
Backslash \ is an escape character
If there is a Chinese character, it will transcode urlencode first and then urldecode, and there will be no \ Chinese character.
Although there is no key name, isn't it?
The writing method of JS arrays is different from that of PHP, not key name =, but separated
Var ar = ["upload \/2013 \/05 \/09 \/14303.jpeg", "upload \/2013 \/05 \/09 \/14300.jpeg ", "upload \/2013 \/05 \/09 \/148.jpeg", "upload \/2013 \/05 \/09 \/187.jpeg ", "upload \/2013 \/05 \/09 \/14296.jpeg", "upload \/2013 \/05 \/09 \/203.jpeg"];
The ar [0] here is upload/2013/05/09/14303 .jpeg.
\ Is used to escape/. it is not only '/', but also '*' () 'and other symbols. \ will be added before your output because they are special.
If the key name is a number, it is automatically hidden.