Tips for converting PHP arrays into JSON Arrays

Source: Internet
Author: User

Today, we will introduce you

How to convert a PHP array into a JSON array:

1. After the server transcodes serialized characters from gbk to the UTF-8 required by soap, return the result:

  1. $ Str = array ("body ");
  2. $ Serializeserialize_str =
    Serialize ($ str );
  3. $ Res = iconv ("GBK", "UTF-8"
    , $ Serialize_str );
  4. Return $ res;

2. In the client side to get the results and then convert the UTF-8 to the GBK page requirements, and then print the array after deserialization is normal without Chinese garbled array:

 
 
  1. $ Iconviconv_str = iconv
    ("UTF-8", "GBK", $ res );
  2. $ Arr = unserialize
    ($ Iconv_str );
  3. Var_dump ($ arr );

The above code example is the full implementation process of converting the PHP array into a JSON array.


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.