I use services_json FOR THE JSON class library of PHP. It has no special advantages or obvious disadvantages.
Create File data. php:
<? PHP
Include ("JSON. php ");
$ DATA = array (
Array ('name' => mb_convert_encoding ('old Wang ', 'utf-8', 'gbk'), 'age' => '28 '),
Array ('name' => mb_convert_encoding ('yellow ', 'utf-8', 'gbk'), 'age' => '27 ')
);
$ JSON = new services_json ();
Echo $ JSON-> encode ($ data );
?>
I use jquery to parse JSON in Javascript. When using Javascript eval directly, note that:
VaR myobject = eval ('+ myjsontext + ')');
For more information, see the following reference link.
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> demo </title>
<SCRIPT type = "text/JavaScript" src = "jquery-latest.pack.js"> </SCRIPT>
<SCRIPT>
$ (Function (){
$. Getjson ("data. php", function (JSON ){
For (VAR I = 0; I <JSON. length; I ++)
{
Alert ("name:" + JSON [I]. Name );
Alert ("Age:" + JSON [I]. Age );
}
});
});
</SCRIPT>
</Head>
<Body>
</Body>
</Html>