Created
July 1, 2019 12:48
-
-
Save junaidtk/7bc6e1b25214b60ca2b1ba6f69c1aa34 to your computer and use it in GitHub Desktop.
JSON data and Its usage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Json means java script object notation. | |
Json is used for transfering the data from cleint side to server or vice versa. | |
Json formate is text only so it can easily send to and from server. | |
In Json data is key value pair, with data separated by comma and | |
curly braces hold object data and square bracket hold array data. | |
Key must be string and written in double quotes. | |
Value must be one of the following | |
* a string | |
* a number | |
* an object (JSON object) | |
* an array | |
* a boolean | |
* null | |
date, function, undefined can't be json value. | |
JSON.parse() | |
============= | |
This function used to convert the json string to java script object. | |
JSON.stringify() | |
================= | |
This function is used to create a json string from java script objects. This function convert dates to string | |
any function exist, this function will remove it. | |
Accessing a Object value using Loop | |
==================================== | |
myObj = { "name":"John", "age":30, "car":null }; | |
for (x in myObj) { | |
document.getElementById("demo").innerHTML += myObj[x]; | |
} | |
In PHP | |
####### | |
json_encode | |
=========== | |
Convert the PHP object to json string | |
json_decode | |
============ | |
Convert the json string to object. | |
// https://stackoverflow.com/questions/383692/what-is-json-and-why-would-i-use-it | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment