Question about converting json_encode array to json-php Tutorial

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.