日期:2014-05-16 浏览次数:20453 次
<?php $arr=array( 'username' => 'foo', 'password' => 'bar' ); echo json_encode($arr); ?>
<?php $jsonstring=$_POST["jsonstring"]; $jsondata=json_decode(stripslashes($jsonstring),true); echo $jsondata["password"]; ?>
var jsonURL="http://localhost/json/test.php"; var jsonURL1="http://localhost/json/test1.php"; function Start(){ //获取json数据的方法 var getwww : WWW = new WWW (jsonURL); yield getwww; var jsonObj1=eval(getwww.data); print (jsonObj1["username"]); //提交JSON数据的方法 var mydata=new Boo.Lang.Hash(); mydata["username"]="hello"; mydata["password"]="world"; //将数据转换为json字符串 var jsonstring=ToJSON(mydata); var form = new WWWForm(); form.AddField("jsonstring", jsonstring); var postwww: WWW = new WWW(jsonURL1, form); yield postwww; print(postwww.data); } /** * 转换JSON */ static function ToJSON(obj){ if (obj==null) return "null"; var results=new Array(); for (var property in obj){ results.push("\""+property.Key+"\" : \""+property.Value+"\""); } return "{"+results.join(" , ")+"}"; }
<?php $arr=array( 'username' => '测试', 'password' => 'bar' ); echo js_unescape(json_encode($arr)); function js_unescape($str) { $ret = ''; $len = strlen($str); for ($i = 0; $i < $len; $i++) { if ($str[$i] == '\\' && $str[$i+1] == 'u') { $val = hexdec(substr($str, $i+2, 4)); if ($val < 0x7f) $ret .= chr($val); else if($val < 0x800) $ret .= chr(0xc0|($val>>6)).chr(0x80|($val&0x3f)); else $ret .= chr(0xe0|($val>>12)).chr(0x80|(($val>>6)&0x3f)).chr(0x80|($val&0x3f)); $i += 5; } else $ret .= $str[$i]; } return $ret; } ?>
var jsonURL="http://localhost/json/demo.php"; var show; var chineseSkin : GUISkin; function Start(){ //获取json数据的方法 var