JSON and A Comparison of Scripts
description
Transcript of JSON and A Comparison of Scripts
![Page 1: JSON and A Comparison of Scripts](https://reader036.fdocuments.us/reader036/viewer/2022083007/56814095550346895dac2b49/html5/thumbnails/1.jpg)
JSONJSONandand
A Comparison of ScriptsA Comparison of Scripts
![Page 2: JSON and A Comparison of Scripts](https://reader036.fdocuments.us/reader036/viewer/2022083007/56814095550346895dac2b49/html5/thumbnails/2.jpg)
JSON: JavaScript Object Notation
• Based on a subset of the JavaScript Programming Language
• provides a standardized data exchange format that is better-suited for Ajax-style web applications.
formal languages specifically designed to support the communication of data and metadata.
![Page 3: JSON and A Comparison of Scripts](https://reader036.fdocuments.us/reader036/viewer/2022083007/56814095550346895dac2b49/html5/thumbnails/3.jpg)
JSON: JavaScript Object Notation
• Language independant, but similar to C-family (C, Java, Perl, Python)
• Data formatted according to the JSON standard is lightweight and can be parsed by JavaScript implementations with incredible ease
![Page 4: JSON and A Comparison of Scripts](https://reader036.fdocuments.us/reader036/viewer/2022083007/56814095550346895dac2b49/html5/thumbnails/4.jpg)
JSON: JavaScript Object Notation
• Built on two structures:• Name/value pair• Ordered list of values
![Page 5: JSON and A Comparison of Scripts](https://reader036.fdocuments.us/reader036/viewer/2022083007/56814095550346895dac2b49/html5/thumbnails/5.jpg)
JSON literals
![Page 6: JSON and A Comparison of Scripts](https://reader036.fdocuments.us/reader036/viewer/2022083007/56814095550346895dac2b49/html5/thumbnails/6.jpg)
JSON: the difference
• JSON: much stricter rules. • name of an object member must be a valid JSON
string. • string must be enclosed in quotation marks.• array and object elements are limited to a set.
• No date/time literal (not in JavaScript either)
• No comments
![Page 7: JSON and A Comparison of Scripts](https://reader036.fdocuments.us/reader036/viewer/2022083007/56814095550346895dac2b49/html5/thumbnails/7.jpg)
Using JSON
• Use a script tag<script src="http://www.mysite.com/mydata.js"></script>
• Dynamically load a script tagfunction dhtmlLoadScript(url)
{
var e = document.createElement("script");
e.src = url;
e.type="text/javascript";
document.getElementsByTagName("head")[0].appendChild(e);
}
dhtmlLoadScript("http://www.mysite.com/mydata.js");
![Page 8: JSON and A Comparison of Scripts](https://reader036.fdocuments.us/reader036/viewer/2022083007/56814095550346895dac2b49/html5/thumbnails/8.jpg)
Using JSON
• Use AJAX to pull some text from the server and then eval it.
ajaxCaller.getPlainText("mydata.js", function(jsText)
{ eval(jsText); });
![Page 9: JSON and A Comparison of Scripts](https://reader036.fdocuments.us/reader036/viewer/2022083007/56814095550346895dac2b49/html5/thumbnails/9.jpg)
Server vs Client Side Scripting
![Page 10: JSON and A Comparison of Scripts](https://reader036.fdocuments.us/reader036/viewer/2022083007/56814095550346895dac2b49/html5/thumbnails/10.jpg)
Client-side Scripting
• Easy way to provide additional functionality and flexibility
• Downloaded, interpreted and executed by the browser
• Dependant on the client's capabilities (memory, CPU speed, video card)
• Lightweight, less full-featured language
• Examples: JavaScript, JScript, VBScript
![Page 11: JSON and A Comparison of Scripts](https://reader036.fdocuments.us/reader036/viewer/2022083007/56814095550346895dac2b49/html5/thumbnails/11.jpg)
Server-side Scripting
• Also enhances functionality, but usually less visible
• Used for content management (database)
• Runs on the server and depends on memory and CPU speed of the server
• Must be supported by the server
• Examples: PHP, ASP, Perl