Home >Backend Development >PHP Tutorial >A brief discussion on JSON data operations in PHP, a brief discussion on phpjson data_PHP tutorial
JSON, the full name is JavaScript Object Notation. It is a lightweight data exchange format based on the JavaScript programming language ECMA-262 3rd Edition-December 1999 standard, which is mainly used to exchange data with the server. Similar to XML, it is language independent and has great advantages in cross-platform data transmission
Create a new file json.php and do the encode operation first:
//encode //生成JSON格式数据 $arr = array(1,2,3,4,5,6,7,8,9,'Hello','PHP'); echo json_encode($arr);//json_encode:把一个对象转换成json格式数据
The result is [1,2,3,4,5,6,7,8,9,"Hello","PHP"]
Do the decoding operation again:
//decode 解码 $jsonStr = '{"h":"Hello","w":"World","0":[3,2,1]}'; $obj = json_decode($jsonStr); echo $obj->h;//使用成员访问的方式就可以得到结果
After you know the simple usage method, you can try to capture API data, such as weather...
The above is the entire content of this article, I hope you all like it.