Uyisebenzisa kanjani i-PHP ukubuyisa umhla kwifomathi yeJSON

NguSteve Suehring, uJanet Valade

IJavaScript Object Notation (JSON) yindlela yokutshintshiselana ngedatha phakathi kweenkonzo zewebhu ngendlela elula necacileyo, ngaphandle kwayo yonke into engaphezulu kweXML. IJSON yindlela entle yokudibanisa inkonzo yewebhu kunye neJavaScript kuba iJSON inokuhanjiswa ngokulula ngekhowudi yeJavaScript. Ngcono nangakumbi, i-PHP ibandakanya imisebenzi yemveli kuzo zombini ukudala nokufunda iJSON.



Le misebenzi,json_encode ()kwayejson_decode (), yenza kube lula ukusebenza neJSON kunye nokwenza iinkonzo zewebhu zeJSON kwi-PHP.



Indlela elula yokwenza iinyawo zakho zimanzi ngeenkonzo zewebhu kukubuyisa umhla kwifomathi yeJSON. Nantsi indlela onokuyenza ngayo:

  1. Vula umhleli wakho wokubhaliweyo okanye inkqubo ye-IDE kwaye wenze ifayile entsha engenanto.



    umfanekiso0.jpg

  2. Beka le khowudi ilandelayo kwifayile:

  3. Gcina le fayile njenge-date.php kwingcambu yomncedisi wewebhu.



    ide kangakanani i-thc emchameni

    umfanekiso1.jpg

  4. Jonga iphepha kwisikhangeli sakho sewebhu ku-http: // yobulali / umhla.php.

    Kuya kufuneka ubone iphepha elinje liboniswe apha (nangona umhla uya kwahluka).

    umfanekiso2.jpg

    Eli phepha liqulathe umhla obhalwe ngekhowudi weJSON. Lo mhla ungadluliswa kunye neJavaScript okanye ude usetyenziswe kwenye inkqubo ye-PHP. Qaphela ukusetyenziswa kweisicelo./jsonnjengesihloko seHTTP. Oku kubaluleke kakhulu ukwazisa inkqubo yokufowuna (nokuba yiJavaScript okanye i-PHP) ekufuneka ilindele ukufumana impendulo yeJSON ngokuchasene ne-HTML, i-XML, okanye olunye uhlobo lokuphendula.