PHP Json data parsing - Web Development
7 Views

PHP Json data parsing

Json is a text-based format like xml . JSON is easy to read and easy to understand for humans and computers but Json occupy less bandwith compare to xml . JSON is the most popular and lightweight data-interchange format for website applications. Below is json object

JSON data structures are very similar to PHP arrays. Encoding and decoding of json data in php is very easy .PHP uses these two functions json_encode() and json_decode() for encoding and decoding of json data . Both functions only works with UTF-8 .

We have seen Json object , Now below is Json array inside Json object

How to encode Json data in php : – json_encode() function is uses to encode data to json format . The below example explanes how to use json_encode() in php for associative array .

Output of this code

{“Peter”:65,”Harry”:80,”John”:78,”Clark”:90}

How to decode Json data in php :-

Decoding json value is as simple as encoding .Now here we will use php json_decode() function convert the json encoded string to php data types

Output of code

9002020
23030030
78020292

See more tutorials on json & php

Leave a Reply

Your email address will not be published. Required fields are marked *