Printing data retrieved from json file
In our previous tutorials we have shown you how to retrieve database information, encode and print it to json file. Now, we will learn how to decode the same json file and print it to user interface stream. If you look and json data format below this is exactly what we retrieve from our database. Put the json file in the same folder where the next php code will be placed. Below is example of our json file named data.json for this testing.
Our php script to grab and open json file
If you look at the php code below it has been prepared ready to copy and paste for testing. First, we will use php function object file_get_contents() to get json file and use php function object json_decode() to decode json file and print it on user interface stream. Now, copy the code below save it as jsondecode.php and run it to see the output.
".$image."
"; echo "".$fullname."
"; echo "".$fulladdress."
"; echo "".$emailaddress."
"; echo "".$phonenumber."
"; echo "".$username."
"; echo "".$password."
"; echo "".$project."
"; echo "".$subscription."
"; echo "".$gender."
"; echo "".$reg_date."
"; ?>Json decode data on user interface stream
After decoding json data the below is the output of our json file. If the above return error or if you see error message from php, let us know so will look into it.
Summary
In the above tutorials almost everything is already made for testing purposes. If you encounter error don't hesitate to post your question in comment box below. We are ready to answer your questions. Thanks for reading and practicing with us.
Comments