| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> php >> JSON zai PHP zhong de ying yong

JSON zai PHP zhong de ying yong

2008-12-23 08:12:43 编辑來源:互联网 评论
 
 
 
本文为【JSON在PHP中的应用】的拼音翻译版
  hu lian wang de jin tian ,AJAX yi jing bu shi shen me mo sheng de ci hui le 。 shuo qi AJAX, ke neng hui li ji xiang qi yin RSS er xing qi de XML。XML de jie xi , kong pa yi jing bu shi shen me nan ti le , te bie shi PHP5, da liang de XML jie xi qi de yong xian , ru zui qing liang ji de SimpleXML。 bu guo dui yu AJAX lai shuo ,XML de jie xi geng qing xiang yu qian tai Javascrīpt de zhi chi du 。 wo xiang suo you jie xi guo XML de ren , dou hui yin shu he jie dian er tou da 。 bu ke fou ren ,XML shi hen bu cuo de shu ju cun chu fang shi , dan shi qi ling huo qia qia zao cheng le qi jie xi de kun nan 。 dang ran , zhe li suo zhi de kun nan , shi xiang dui yu ben wen de zhu jiao --JSON er yan 。
  JSON wei he wu ? wo jiu bu chong fu gai nian le 。 tong su de shuo , ta shi yi zhong shu ju de cun chu ge shi , jiu xiang PHP xu lie hua hou de zi fu chuan yi yang 。 ta shi yi zhong shu ju miao shu 。 bi ru wo men jiang yi ge shu zu xu lie hua hou cun fang , jiu ke yi hen rong yi de fan xu lie hua hou ying yong 。JSON ye shi ru ci , zhi bu guo ta da jian de shi ke hu duan Javascrīpt he fu wu duan PHP de jiao hu qiao liang 。 wo men yong PHP sheng cheng JSON hou de zi fu chuan , ran hou ba zhe ge zi fu chuan chuan gei qian tai Javascrīpt,Javascirpt jiu ke yi hen rong yi de jiang qi fan JSON ran hou ying yong 。 shuo tong su dian , ta zhen de hen xiang shu zu 。
  yan gui zheng chuan , ru he shi yong JSON。PHP5.2 kai shi nei zhi le JSON de zhi chi 。 dang ran , ru guo di yu zhe ge ban ben de hua , na me shi mian shang you hen duo PHP ban ben de shi xian , sui bian xia yi ge yong jiu OK la 。 xian zai zhu yao shi shuo shuo PHP nei zhi zhi chi de JSON。 hen jian dan , liang ge han shu :json_encode he json_decode( gen xu lie hua hen xiang la )。 yi ge bian ma , yi ge jie ma 。 xian kan kan bian ma de shi yong :
  <?php
  $arr = array(
   'name' => ' chen yi xin ',
   'nick' => ' shen kong ',
   'contact' => array(
   'email' => 'shenkong at qq dot com',
   'website' => 'http://www.devdao.com',
   )
  );
  $json_string = json_encode($arr);
  echo $json_string;
  ?> hen jian dan de jiang yi ge shu zu JSON le 。 xu yao zhi chu de shi , zai fei UTF-8 bian ma xia , zhong wen zi fu jiang bu ke bei encode, jie guo hui chu lai kong zhi , suo yi , ru guo ni shi yong gb2312 bian xie PHP dai ma , na me jiu xu yao jiang bao han zhong wen de nei rong shi yong iconv huo zhe mb zhuan wei UTF-8 zai jin xing json_encode, shang mian shu chu jie guo ru xia :
  {"name":"\u9648\u6bc5\u946b","nick":"\u6df1\u7a7a","contact":{"email":"shenkong at qq dot com","website":"http:\/\/www.devdao.com"}} wo dou shuo le he xu lie hua hen xiang , ni huan bu xin 。 bian ma hou jiu yao jie ma ,PHP ti gong le xiang ying de han shu json_decode,json_decode zhi xing hou , jiang hui de dao yi ge dui xiang , cao zuo ru xia :
  <?php
  $arr = array(
   'name' => ' chen yi xin ',
   'nick' => ' shen kong ',
   'contact' => array(
   'email' => 'shenkong at qq dot com',
   'website' => 'http://www.devdao.com',
   )
  );
  $json_string = json_encode($arr);
  $obj = json_decode($json_string);
  print_r($obj);
  ?> fang wen dui xiang nei de shu xing hui ba ?$obj->name, zhe yang zi de , dang ran , ye ke yi ba ta zhuan wei shu zu , fang bian tiao yong la :
  $json_string = json_encode($arr);
  $obj = json_decode($json_string);
  $arr = (array) $obj;
  print_r($arr);PHP zhuan lai zhuan qu de yong tu bu shi te bie da , chu le huan cun sheng cheng , gan jiao huan bu ru zhi jie cun shu zu ne , bu guo , dang ni he qian tai jiao hu de shi hou , ta de zuo yong jiu chu lai ge , xia mian kan kan wo zen me yong Javascrīpt lai shi yong zhe duan zi fu :
  <scrīpt type="text/javascrīpt">
  var arr = {"name":"\u9648\u6bc5\u946b","nick":"\u6df1\u7a7a","contact":{"email":"shenkong at qq dot com","website":"http:\/\/www.devdao.com"}};
  alert(arr.name)
  </scrīpt> shang mian zhong , zhi jie jiang zhe ge zi fu chuan fu gei yi ge bian liang , ta jiu bian cheng yi ge Javascrīpt shu zu le ( zhuan ye hua shu yu ying gai bu jiao shu zu , bu guo you yu PHP de xi guan wen ti , wo jiu yi zhi jiao shu zu hao le , fang bian li jie )。 zhe yang , ke yi hen fang bian de dui arr jin xing bian li huo zhe ren yi zuo ni xiang zuo de shi qing le 。 xie dao zhe li , hao xiang dou mei ti dao AJAX o ? shi o , lian xiang yi xia , ru guo fu wu duan fan hui de responseText yong JSON guo de zi fu chuan dai ti XML de hua , qian tai Javascrīpt chu li qi lai shi bu shi hen fang bian ne ? gou pi gao yao jiu shi zhe yang yong de 。
  qi shi xie dao zhe li , chu le shu ju de cun chu ge shi bu tai yi yang wai ,JSON he XML ye mei shen me tai da qu bie o , bu guo xia mian wo shuo de yi dian 。 sui ran he XML mei duo da guan xi , bu guo , ke yi shuo ming JSON geng da fan wei de ying yong , na jiu shi , kua yu de shu ju tiao yong 。 you yu an quan xing wen ti ,AJAX bu zhi chi kua yu tiao yong , zhe yang yao tiao yong bu tong yu ming xia de shu ju , hen ma fan o , sui ran you jie jue fang an (stone zai ta de jiang zuo shang ti dao guo le dai li a shen me de sui ran ting bu dong dan shi zhi dao neng jie jue )。 wo xie liang ge wen jian , zu yi zhan shi kua yu tiao yong le 。
  zhu tiao wen jian index.html
  <scrīpt type="text/javascrīpt">
  function getProfile(str) {
   var arr = str;
   document.getElementById('nick').innerHTML = arr.nick;
  }
  </scrīpt>
  <body><div id="nick"></div></body>
  <scrīpt type="text/javascrīpt" src="http://www.openphp.cn/demo/profile.php"></scrīpt> bei tiao wen jian profile.php
  <?php
  $arr = array(
   'name' => ' chen yi xin ',
   'nick' => ' shen kong ',
   'contact' => array(
   'email' => 'shenkong at qq dot com',
   'website' => 'http://www.devdao.com',
   )
  );
  $json_string = json_encode($arr);
  echo "getProfile($json_string)";
  ?> hen xian ran , dang index.html tiao yong profile.php shi ,JSON zi fu chuan sheng cheng , bing zuo wei shen shu chuan ru getProfile, ran hou jiang ni cheng cha ru dao div zhong , zhe yang yi ci kua yu shu ju jiao hu jiu wan cheng le , shi bu shi te bie jian dan 。 ji ran JSON zhe me jian dan yi yong er qie hao yong , huan deng shen me ne【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
   hu lian wang de jin tian ,AJAX yi jing bu shi shen me mo sheng de ci hui le 。 shuo qi AJAX, ke neng hui li ji xiang qi yin RSS er xing qi de XML。XML de jie xi , kong pa yi jing bu shi shen me nan ti le , te bie shi PHP5, da liang de XML jie xi qi de yong xian , ru zui qing liang ji de SimpleXML。 bu guo dui yu AJAX lai shuo ,XML de jie xi geng qing xiang yu qian tai Javascrīpt de zhi chi du 。 wo xiang suo you jie xi guo XML de ren , dou hui yin shu he jie dian er tou da 。 bu ke fou ren ,XML shi hen bu cuo de shu ju cun chu fang shi , dan shi qi ling huo qia qia zao cheng le qi jie xi de kun nan 。 dang ran , zhe li suo zhi de kun nan , shi xiang dui yu ben wen de zhu jiao --JSON er yan 。   JSON wei he wu ? wo jiu bu chong fu gai nian le 。 tong su de shuo , ta shi yi zhong shu ju de cun chu ge shi , jiu xiang PHP xu lie hua hou de zi fu chuan yi yang 。 ta shi yi zhong shu ju miao shu 。 bi ru wo men jiang yi ge shu zu xu lie hua hou cun fang , jiu ke yi hen rong yi de fan xu lie hua hou ying yong 。JSON ye shi ru ci , zhi bu guo ta da jian de shi ke hu duan Javascrīpt he fu wu duan PHP de jiao hu qiao liang 。 wo men yong PHP sheng cheng JSON hou de zi fu chuan , ran hou ba zhe ge zi fu chuan chuan gei qian tai Javascrīpt,Javascirpt jiu ke yi hen rong yi de jiang qi fan JSON ran hou ying yong 。 shuo tong su dian , ta zhen de hen xiang shu zu 。    yan gui zheng chuan , ru he shi yong JSON。PHP5.2 kai shi nei zhi le JSON de zhi chi 。 dang ran , ru guo di yu zhe ge ban ben de hua , na me shi mian shang you hen duo PHP ban ben de shi xian , sui bian xia yi ge yong jiu OK la 。 xian zai zhu yao shi shuo shuo PHP nei zhi zhi chi de JSON。 hen jian dan , liang ge han shu :json_encode he json_decode( gen xu lie hua hen xiang la )。 yi ge bian ma , yi ge jie ma 。 xian kan kan bian ma de shi yong : <?php $arr = array( 'name' => ' chen yi xin ', 'nick' => ' shen kong ', 'contact' => array( 'email' => 'shenkong at qq dot com', 'website' => 'http://www.devdao.com', ) ); $json_string = json_encode($arr); echo $json_string; ?>   hen jian dan de jiang yi ge shu zu JSON le 。 xu yao zhi chu de shi , zai fei UTF-8 bian ma xia , zhong wen zi fu jiang bu ke bei encode, jie guo hui chu lai kong zhi , suo yi , ru guo ni shi yong gb2312 bian xie PHP dai ma , na me jiu xu yao jiang bao han zhong wen de nei rong shi yong iconv huo zhe mb zhuan wei UTF-8 zai jin xing json_encode, shang mian shu chu jie guo ru xia : {"name":"\u9648\u6bc5\u946b","nick":"\u6df1\u7a7a","contact":{"email":"shenkong at qq dot com","website":"http:\/\/www.devdao.com"}}   wo dou shuo le he xu lie hua hen xiang , ni huan bu xin 。 bian ma hou jiu yao jie ma ,PHP ti gong le xiang ying de han shu json_decode,json_decode zhi xing hou , jiang hui de dao yi ge dui xiang , cao zuo ru xia : <?php $arr = array( 'name' => ' chen yi xin ', 'nick' => ' shen kong ', 'contact' => array( 'email' => 'shenkong at qq dot com', 'website' => 'http://www.devdao.com', ) ); $json_string = json_encode($arr); $obj = json_decode($json_string); print_r($obj); ?>   fang wen dui xiang nei de shu xing hui ba ?$obj->name, zhe yang zi de , dang ran , ye ke yi ba ta zhuan wei shu zu , fang bian tiao yong la : $json_string = json_encode($arr); $obj = json_decode($json_string); $arr = (array) $obj; print_r($arr);  PHP zhuan lai zhuan qu de yong tu bu shi te bie da , chu le huan cun sheng cheng , gan jiao huan bu ru zhi jie cun shu zu ne , bu guo , dang ni he qian tai jiao hu de shi hou , ta de zuo yong jiu chu lai ge , xia mian kan kan wo zen me yong Javascrīpt lai shi yong zhe duan zi fu : <scrīpt type="text/javascrīpt"> var arr = {"name":"\u9648\u6bc5\u946b","nick":"\u6df1\u7a7a","contact":{"email":"shenkong at qq dot com","website":"http:\/\/www.devdao.com"}}; alert(arr.name) </scrīpt>   shang mian zhong , zhi jie jiang zhe ge zi fu chuan fu gei yi ge bian liang , ta jiu bian cheng yi ge Javascrīpt shu zu le ( zhuan ye hua shu yu ying gai bu jiao shu zu , bu guo you yu PHP de xi guan wen ti , wo jiu yi zhi jiao shu zu hao le , fang bian li jie )。 zhe yang , ke yi hen fang bian de dui arr jin xing bian li huo zhe ren yi zuo ni xiang zuo de shi qing le 。 xie dao zhe li , hao xiang dou mei ti dao AJAX o ? shi o , lian xiang yi xia , ru guo fu wu duan fan hui de responseText yong JSON guo de zi fu chuan dai ti XML de hua , qian tai Javascrīpt chu li qi lai shi bu shi hen fang bian ne ? gou pi gao yao jiu shi zhe yang yong de 。    qi shi xie dao zhe li , chu le shu ju de cun chu ge shi bu tai yi yang wai ,JSON he XML ye mei shen me tai da qu bie o , bu guo xia mian wo shuo de yi dian 。 sui ran he XML mei duo da guan xi , bu guo , ke yi shuo ming JSON geng da fan wei de ying yong , na jiu shi , kua yu de shu ju tiao yong 。 you yu an quan xing wen ti ,AJAX bu zhi chi kua yu tiao yong , zhe yang yao tiao yong bu tong yu ming xia de shu ju , hen ma fan o , sui ran you jie jue fang an (stone zai ta de jiang zuo shang ti dao guo le dai li a shen me de sui ran ting bu dong dan shi zhi dao neng jie jue )。 wo xie liang ge wen jian , zu yi zhan shi kua yu tiao yong le 。    zhu tiao wen jian index.html <scrīpt type="text/javascrīpt"> function getProfile(str) { var arr = str; document.getElementById('nick').innerHTML = arr.nick; } </scrīpt> <body><div id="nick"></div></body> <scrīpt type="text/javascrīpt" src="[url=http://www.openphp.cn/demo/profile.php]http://www.openphp.cn/demo/profile.php"></scrīpt[/url]>   bei tiao wen jian profile.php <?php $arr = array( 'name' => ' chen yi xin ', 'nick' => ' shen kong ', 'contact' => array( 'email' => 'shenkong at qq dot com', 'website' => 'http://www.devdao.com', ) ); $json_string = json_encode($arr); echo "getProfile($json_string)"; ?>   hen xian ran , dang index.html tiao yong profile.php shi ,JSON zi fu chuan sheng cheng , bing zuo wei shen shu chuan ru getProfile, ran hou jiang ni cheng cha ru dao div zhong , zhe yang yi ci kua yu shu ju jiao hu jiu wan cheng le , shi bu shi te bie jian dan 。 ji ran JSON zhe me jian dan yi yong er qie hao yong , huan deng shen me ne
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
时尚秀气模特裴裴(8)
时尚秀气模特裴裴(7)
时尚秀气模特裴裴(6)
时尚秀气模特裴裴(5)
白墙黑瓦
广州东郊[原创]
八美至丹巴的东谷天然盆景
不一样的
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有