An array-to-json question about Json_encode

Source: Internet
Author: User
I'm going to convert an array to JSON.
The array was originally output like this
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 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 "]

What's going on, why doesn't JSON have keys? Not supposed to be "0": Upload/2013/05/09/14303.jpeg? and the original array of the URL in the memory of many more "\" originally only "/", this is what is going on?


Reply to discussion (solution)

JSON data format is like this, JS in the call is no problem.

JSON data format is like this, JS in the call is no problem.
But I see the online tutorials are not all "0": Upload/2013/05/09/14303.jpeg like this? And what is the reason for this "\" appearance?


JSON data format is like this, JS in the call is no problem.
But I see the online tutorials are not all "0": Upload/2013/05/09/14303.jpeg like this? And what is the reason for this "\" appearance?

Backslash \ is an escape character

If there is a Chinese will transcode first UrlEncode and then UrlDecode no \ Chinese is ok

It's not a key name, but it doesn't, does it?
JS array of syntax and PHP still have a certain difference, not the key name = "Key value, but with, 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";
This ar[0] is upload/2013/05/09/14303.jpeg.

\ is to escape/use, more than/and * () and other symbols are added in front of your output, because they are more special

If the key name is a number, it is automatically hidden

  • Related Article

    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.