JSON in PHP

Source: Internet
Author: User
This is a good news. php 5.2 support JSON. It's very easy to use. I like it, because I can transfer data between JavaScript and PHP freely accroading to this functions.

Json_encode

(PHP 5> = 5.2.0, pecl json: 1.2.0-1.2.1)

Json_encode-returns the JSON representation of a value

Description

StringJson_encode(Mixed $ value)

Returns a string containing the JSON representationValue.

Parameters

Value

TheValueBeing encoded. can be any type before t a resource.

This function only works with UTF-8 encoded data.

Return values

Returns a JSON encoded string on success.

Json_decode

(PHP 5> = 5.2.0, pecl json: 1.2.0-1.2.1)

Json_decode-decodes a JSON string

Description

MixedJson_decode(String $ JSON [, bool $ assoc])

Takes a JSON encoded string and converts it into a PHP variable.

Parameters

JSON

TheJSONString being decoded.

Assoc

WhenTrue, Returned objects will be converted into associative arrays.

Return values

Returns an object or if the optionalAssocParameter isTrue, An associative array is instead returned.

Please link to www.php.net for more information.

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.