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:
- $ filepath = $_server[' Document_root '];
- include $filepath. ' /inc/json/encoder. PHP';
- $ Encoder New Zend_json_encoder (false);
- $ 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.
http://www.bkjia.com/PHPjc/446104.html www.bkjia.com true http://www.bkjia.com/PHPjc/446104.html 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 ...