How to correctly resolve PHP missing JSON package problem _php Tutorial

Source: Internet
Author: User
Tags php json zend framework

An alternative to this problem is to rewrite the PHP json Json_decode and Json_encode methods.

The solution to these two PHP-missing JSON packages is to convert arrays, strings, or objects into JSON-formatted data (a special kind of structural physique). The first thing you need is the Json_encode method, which converts arrays, strings, objects, and so on into JSON format. Ways to resolve this problem:

A. Simple version:

Directly for your own problem (you just need to manipulate a simple array), you can simply string the array.

B. Perfect method of encode:

An easy way to solve the problem with PHP missing JSON packages is to use the open source code that someone else has done:

First think of the Zend Framework. Take the decoder.php in the Zf_json bag, and encoder.php. Decoder.php in fact, as long as one of the Protect method to remove the protect on the line. The specific operation forgot, the reader self-debugging to solve. After rewriting the decoder class, the call is as follows:

  1. $ filepath = $_server[' Document_root '];
  2. include $filepath. ' /inc/json/encoder. PHP';
  3. $ Encoder New Zend_json_encoder (false);
  4. $ JSON = $encoder- > encode ($result);

Json_decode method, if PHP is used.

Some Ajax ' frameworks ' provide a decode way to solve the problem of PHP missing JSON packages because many of the JSON-using locations are in Ajax calls:

For example, in prototype, if the PHP page contains prototype.js, then you can call function (transport, JSON) {. Operation} in which JSON data is JSON.A, json.b and so on.

In addition to the problem of PHP missing JSON package, may encounter problems, encoding.

The Chinese character coding estimate returned by the Zend Framework does not correspond (not to say it is not utf-8) to my page encoding (UTF-8), so there will be a problem. As a result, some validation returns an error message (kanji). The alternative here is to use the traditional interface to return the digital code form (the method commonly used by the communication gateway), such as returning Json.code with 0,1,2,3 and many other possibilities. When processing on the JS side, 0 indicates success, 1 indicates illegal client data, and so on. The problem has been solved perfectly. true techarticle An alternative to this problem is to rewrite the PHP json Json_decode and Json_encode methods. The main solution to these two PHP missing JSON packages is to convert the array, string, or object ...

  • 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: 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.