Home  >  Article  >  Backend Development  >  Detailed introduction to PHP JSON class library application examples_PHP tutorial

Detailed introduction to PHP JSON class library application examples_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:33:02750browse

JSON is a lightweight data format developed by Douglas Crockford, a senior software engineer. Its full name is Javascript Object Notation. The Chinese translation is "JavaScript object representation". Data in this format can be easily converted into JavaScript object format, which is used for data transfer between the server and the client. It is used to solve the excessive data transmission volume caused by excessive redundant tags in xml. Big question.

PHP JSON class library is a PHP open source code tool that automatically completes JSON encoding and decoding.

Download: http://www.eb163.com/code/json.rar

The TEST_JSON.php contains PHPUnit.php, which is the unit testing tool that comes with PEAR. It may not be used in actual development.

PHP JSON class library sample code:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?  </span></span></li><li><span>//create a new instance of Services_JSON  </span></li><li class="alt"><span>require_once('JSON.php');  </span></li><li><span>$</span><span class="attribute">json</span><span> = </span><span class="attribute-value">new</span><span> Services_JSON();  </span></li><li class="alt"><span>// convert a complex value to JSON notation  </span></li><li><span>$</span><span class="attribute">value</span><span> = </span><span class="attribute-value">array</span><span>('name'=</span><span class="tag">></span><span>'coollzh'<br>,'age'=</span><span class="tag">></span><span> 22,'data'=</span><span class="tag">></span><span>'foo');  </span></span></li>
<li class="alt">
<span>$</span><span class="attribute">output</span><span> = $json-</span><span class="tag">></span><span>encode($value);  </span>
</li>
<li><span>print($output);  </span></li>
<li class="alt">
<span>//采用post方式发送数据: </span><span class="attribute">json</span><span>=<br>{"name":'coollzh',"age":2,"data":"foo"}  </span>
</li>
<li><span>print($_REQUEST['json']);  </span></li>
<li class="alt">
<span>$</span><span class="attribute">value</span><span>= $json-</span><span class="tag">></span><span>decode(str_replace<br>('\','',$_REQUEST["json"]));   </span>
</li>
<li><span>var_dump( $value);  </span></li>
<li class="alt">
<span>echo "</span><span class="tag"><</span><span> </span><span class="tag-name">br</span><span class="tag">></span><span>".$value-</span><span class="tag">></span><span>data;  </span>
</li>
<li>
<span class="tag">?></span><span> </span>
</li>
</ol>

I hope you can have a preliminary understanding of its specific meaning through the above code examples of the PHP JSON class library.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446096.htmlTechArticleJSON is a lightweight data format developed by Douglas Crockford, a senior software engineer, and its full name is Javascript Object Notation. Chinese translation is JavaScript object representation, this format...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn