Introduction
As we know Ajax is a web development technology that makes the server responses faster by enabling the client-side scripts to retrieve only the required data from the server without retrieving a complete web page on each request, which will minimize the data transferred from the server.
These requests usually retrieve xml formatted response, the xml responses are then parsed in the JavaScript code to render the results. Which complicate the JavaScript code
The idea of JSON (JavaScript Object Notation) is to make the response a specific data structure that can be easily parsed by the JavaScript code.
Advantages
1- lightweight data-interchange format
2- Easy for humans to read and write
3- Easy for machines to parse and generate
4- JSON can be parsed trivially using the eval() procedure in JavaScript
5- JSON Supports: ActionScript, C, C#, ColdFusion, E, Java, JavaScript, ML, Objective CAML, Perl, PHP, Python, Rebol, Ruby, and Lua.
.
Syntax
The JSON Syntax is the convention which you will use it to generate data, it’s near to the C family language, so it can be parsed easily in the C family languages.
For objects start the object with “{“ and end it with “}”
object
{}
{ members }
· For members (properties), use pairs of string : value and separate them by commas
members
string : value
members , string : value
· For arrays put the arrays between []
array
[]
[ elements ]
· For elements put the values directly separated by commas
elements
value
elements , value
· Values can be string, number, object, array, true, false, null
EXAMPLES
JSON
{"menu": {
"id": "file",
"value": "File:",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"} ]
}
}}
XML
<menu id="file" value="File" >
<popup>
<menuitem value="New" onclick="CreateNewDoc()" />
<menuitem value="Open" onclick="OpenDoc()" />
<menuitem value="Close" onclick="CloseDoc()" />
</popup>
</menu>
Server side code
The following code will be generated in the server side to retrieve the server time, and in one step in the client side it will be rendered to JavaScript
Java
<%@ page language="java" import="java.util.*" %>
<%Date date = new Date(); %>alert("The server time is: <%Úte%>");
<SPAN style="mso-tab-count: 1"> ASP.NET
<%@ page language="C#" %> alert("The server time is: <%=System.Date.Now.ToString()%>");
PHP
alert("The server time is: <?=time()?>");
Client Side
JavaScript
//XMLHttpRequest completion function
var myOnComplete = function(responseText, responseXML){eval(responseText);}
分享到:
相关推荐
1 Introduction JSON MySQL The Example Database How to Use This Book 2 JSON as String Data vs. JSON as a Data Type JSON String Data The JSON Data Type 3 Finding the Path Examining the world_x Data ...
Introduction JSON++ is a light-weight JSON parser, writer and reader written in C++. JSON++ can also convert JSON documents into lossless XML documents. Contributors http://github.com/hjiang ...
Chapter 8, Introduction to Hapi.js, talks about implementing JSON-based configuration in a Hapi server and creating RESTful APIs with the help of the same. Chapter 9, Storing JSON Documents in MongoDB...
JavaScript Object Notation (JSON) is a lightweight, text-based, language-independent data interchange format. It was derived from the ECMAScript Programming Language Standard....1. Introduction
IntroductionJson to Property (Xcode8 Editor Extension)快速把jsonString格式为属性InstallOSX 10.11 only sudo /usr/libexec/xpccachectlDownload, unzip and run -> System Preferences... -> Extensions -> ...
Chapter 3: Introduction - XML, JSON Chapter 4: Introduction to JAX-RS Chapter 5: API Portfolio and Framework Chapter 6: API Platform and Data Handler Chapter 7: API Management and API Client Chapter 8...
train.json 之江电商评论观点挖掘比赛训练数据 比赛链接https://zhejianglab.aliyun.com/entrance/231731/introduction
valid.json 之江电商评论观点挖掘比赛训练数据 比赛链接https://zhejianglab.aliyun.com/entrance/231731/introduction
train_laptop.json 之江电商评论观点挖掘比赛训练数据 比赛链接https://zhejianglab.aliyun.com/entrance/231731/introduction
Gitbook 定制侧边栏Introduction文案插件在 book.json 中加入:{ plugins: ["diy-introduction"], pluginsConfig: { "introduction-text": "封面" }}禁用:{ plugins: ["-diy-introduction"]}
潜移默化的该工具可让您用JSON对象中的值替换字符串。安装 npm install subsy --save-dev如何使用使用String.replace() var subsy = require ( 'subsy' ) ; var introduction = "Hello, my name is @name.full@. ...
DSA / TDE 5简介冒险 ...安装-自动安装程序在FVTT游戏系统菜单中,单击安装模块,然后输入清单URL: https://raw.githubusercontent.com/Plushtoast/dsa5_introduction/master/module.json ://raw.githubusercontent....
DDP简介分布式数据协议 (DDP) 是 Meteor 基于简单 JSON 消息的实时有线协议。 首先,您将了解像 DDP 这样的有状态协议与 HTTP 有何不同。 然后,您将使用节点检查器服务器端调试工具详细了解 DDP 服务器。 最后,...
Introduction to Flutter. Installing Flutter. Your first Flutter App. Dependencies & Packages. Introduction to Widgets & Composition. Stateless Widgets. Stateful Widgets. Basic Material Widgets. Multi...
cars.json使用输入文件cars.json打印。 jq ' . ' cars.json 1.1.1-使用管道输出进行打印。 cat cars.json | jq ' . '1.2-JSON的长度。 jq ' length ' cars.json2.选择对象2.1-打印第一个对象。 jq ' .[0] ' cars....
Grunt 入门 目的 添加和执行案例研究中学到的任务 前提 软件 版本 评论 操作系统 10.8.5 咕噜声 ...$ cd grunt_introduction/case01 ... readJSON ( 'package.json' ) , dirs : { src : 'src' , dist : 'd
2017年12月份DMTF发布的Redfish介绍和综述 主要内容包括: Why REST, HTTP and JSON? What is Redfish? Redfish Resource Map (simplified) 以及发展和相关的接口介绍
Building an API / JSON based route for searching 33 Testing your route in PHPUnit 37 Building a view based route 40 Testing your view based route in PHPUnit 42 Creating named routes 45 Chapter 4: ...
leetcode中国 JavaScript ...Introduction This repository is my small world for learning and practicing JavaScript. Some helpful resources or links will be posted here for use. Learning Path ...
1 Introduction 5 2 Practical Applications 8 3 JSON Web Tokens in Detail 23 4 JSON Web Signatures 30 5 JSON Web Encryption (JWE) 41 6 JSON Web Keys (JWK) 58 7 JSON Web Algorithms 61 8 Annex A. Best ...