Example of php processing json code: PHP implements Baidu translation API call and processing. Today, a small program is written to the background, and Baidu translation API is called to implement translation functions.
The url for calling Baidu API is 'http: // openapi.baidu.com/public/2.0/translate/dict/simple? Client_id = your KEY & q = Chinese to be queried & from = zh & to = EN ';
For details about the application process, click the open link.
The above are preparations
========================================================== ========================================================== ==============================
The json returned by calling Baidu translation API is: {"errno": 0, "data": {"word_name": "\ u4f60 \ u597d", "symbols ": [{"ph_zh": "n \ u01d0 h \ u01ceo", "parts": [{"part": "", "means": ["hello ", "hi", "How do you do! "]}," To ":" en "," from ":" zh "}'
If you have poor eyesight, you can format the string.
{"errno":0,"data":{"word_name":"\u4f60\u597d","symbols":[{"ph_zh":"n\u01d0 h\u01ceo","parts":[{"part":"","means":["hello","hi","How do you do!"]}]}]},"to":"en","from":"zh"}
Key Statement: json_decode ($ jsonResult)-> data-> symbols [0]-> parts [0]
It's also strange that I am too stupid, so I spent one night with such a statement ...... The basics are too important !!!
Obtained through this step
{"part":"","means":["hello","hi","How do you do!"]}
Next pass
$jsonObj->means[0]$jsonObj->means[1]$jsonObj->means[2]
Obtain the three definitions of "Hello.
In actual operations, you can obtain all definitions through cyclic statements.
Below is all the code
Data-> symbols [0]-> parts [0]; echo $ jsonObj-> means [0].'
'; Echo $ jsonObj-> means [1].'
'; Echo $ jsonObj-> means [2].'
';?>
Enter url? S = Hello
Running result