1.0.0 Summary

Tittle:【EatBook】-NO.1.EatBook.1.JavaData.1.001-《JSON 必知必会-Introduction to JavaScript Object Notation》-

Style:Java-Json

Series:O'Reilly Turing

Publishing House:人民邮电

Page Number:129

Since:2017-04-06

End:2017-04-06

Total Hours:4

Degree Of Diffculty:low-2

Degree Of Mastery:frequently-1

Practical Level:A-1

Desired Goal:All relation to JSON

Archieve Goal:foundation usge, secure concept

Gerneral Evaluation:snack book

Read From:EBook

Reader:kingdelee

Source Code:https://github.com/lindsaybassett/json

Related Links:

http://shop.oreilly.com/product/0636920041597.do

https://jsonformatter.curiousconcept.com/

http://jsonlint.com/

http://www.cnblogs.com/kingdelee/

Cover:

1.1.0

Json is a data interchange format

1.2.0 K-V Form

Json is base on JavaScript Object Notation literal(字面量).

{
"brand": "Crocs",
"color": "pink",
"size": 9,
"hasLaces": false
}

1.2.1 Illegal

None of ""

{
title: "This is my title.",
body: "This is the body."
}

Error of ''

{
'title': 'This is my title.',
'body': 'This is the body.'
}

1.2.2 Contain Numbers

Value can be string, number, boolean, null, obj, array.

{
"brand": "Crocs",
"size": 9,
"hasLaces": false,
"color": null
}

1.2.3 MIME

application/json

1.3.1 Emun Form

[
"witty",
"charming",
"brave",
"bold"
]

1.3.2 Object Form

{
"person": {
"name": "Lindsay Bassett",
"heightInInches": 66,
"head": {
"hair": {
"color": "light blond",
"length": "short",
"style": "A-line"
},
"eyes": "green"
}
}
}

1.3.3 Nest ""

Illegal

{
"promo": "Say "Bob's the best!" at checkout for free 8oz bag of kibble."
}

Legal

{
"promo": "Say \"Bob's the best!\" at checkout for free 8oz bag of kibble."
}

1.3.4 BackLash \

Illegal

{
"location": "C:\Program Files"
}

Legal

{
"location": "C:\\Program Files"
}

Escape character:

\/  slash(正斜线)

\b  backward channel(退格符)

\f   form feed character(换页符)

\t   tab character(制表符)

\n   newline(换行符)

\r   carriage return(回车符)

\u   后面跟十六进制字符

1.3.5 array

mixture in array:

{
"eggCarton": [
"egg",
null,
"egg",
"egg",
"egg",
5,
"egg"
]
}

string in array:

{
"students": [
"Jane Thomas",
"Bob Roberts",
"Robert Bobert",
"Thomas Janerson"
]
}

number in array:

{
"scores": [
93.5,
66.7,
87.6,
92
]
}

array nest object:

{
"test": [
{
"question": "The sky is blue.",
"answer": true
},
{
"question": "The earth is flat.",
"answer": false
},
{
"question": "A cat is a dog.",
"answer": false
}
]
}

array nest array:

{
"tests": [
[
true,
false,
false,
false
],
[
true,
true,
true,
true,
false
],
[
true,
false,
true
]
]
}

legal empty json object:

{}

Json array:

[
{
"user": "bobbarker"
},
{
"phone": "555-555-5555"
}
]

legal empty json array:

[]

Point:

1.json array is a executable javascript, explorer will parse and executed:

[{"Id":3,"Name":hyddd,"Money":10000}]

2.json object is not a executable javascript, explorer won't parse and executed:

{"Id":3,"Name":hyddd,"Money":10000}

1.4.0 Schema  

http://json-schema.org/

1.5.0 Secure

CSRF

XSS

1.5.1

Don't use JSON.eval():

<!DOCTYPE html>
<html>
<head>
<title>Introduction to JavaScript Object Notation</title>
<script>
var jsonString = '{"animal":"cat"}';
var myObject = eval("(" + jsonString + ")");
alert(myObject.animal);
</script>
</head>
<body>
<h1>Introduction to JavaScript Object Notation</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Introduction to JavaScript Object Notation</title>
<script>
var jsonString = "alert('this is bad')";
var myObject = eval("(" + jsonString + ")");
alert(myObject.animal);
</script>
</head>
<body>
<h1>Introduction to JavaScript Object Notation</h1>
</body>
</html>

use JSON.parse() in instead of JSON.eval():

<!DOCTYPE html>
<html>
<head>
<title>Introduction to JavaScript Object Notation</title>
<script>
var jsonString = '{"animal":"cat"}';
var myObject = JSON.parse(jsonString);
alert(myObject.animal);
</script>
</head>
<body>
<h1>Introduction to JavaScript Object Notation</h1>
</body>
</html>

1.5.2 Use escape character instead of html code

no secure:

{
"message": "<div onmouseover=\"alert('gotcha!')\">hover here.</div>"
}

secure perhaps:

&lt;div&gt;

1.6.0

serialized and deserialized:

<!DOCTYPE html>
<html>
<head>
<title>Introduction to JavaScript Object Notation</title>
<script>
var myXMLHttpRequest = new XMLHttpRequest();
var url = "http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139";
myXMLHttpRequest.onreadystatechange = function() {
if (myXMLHttpRequest.readyState === 4 && myXMLHttpRequest.status === 200) {
// the JSON response deserialized
var myObject = JSON.parse(myXMLHttpRequest.responseText);
// let's display the weather on the page
var description = "It's " + myObject.weather[0].description + " and " + myObject.main.temp + " degrees in " + myObject.name + ".";
document.getElementById("weather").innerHTML = description; // The object serialized
var myJSON = JSON.stringify(myObject);
// let's display this in the div with the id "json"
document.getElementById("json").innerHTML = myJSON;
}
else if (myXMLHttpRequest.readyState === 4 && myXMLHttpRequest.status !== 200)
{
// fail.
document.getElementById("weather").innerHTML = "failed.";
document.getElementById("json").innerHTML = "failed.";
document.getElementById("error").innerHTML = "Unable to connect to the open weather map API. Are you connected to the internet? Is <a href='http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139'>this page</a> responsing? If it's not, try again later."
}
}
myXMLHttpRequest.open("GET", url, true);
myXMLHttpRequest.send();
</script>
</head>
<body>
<h1>Introduction to JavaScript Object Notation</h1>
<h2>The Weather</h2>
<div id="weather">
loading...
</div>
<h2>The JSON as a String</h2>
<div id="json">
loading...
</div>
<div id="error">
</div>
</body>
</html>

1.6.1 CORS Secure

Insecure:

Access-Control-Allow-Credentials:true
Access-Control-Allow-Methods:GET, POST
Access-Control-Allow-Origin:*

Secure:

Access-Control-Allow-Methods:POST
Access-Control-Allow-Origin:http://www.somebank.com

1.6.2 JSON-P

example10.json:
getTheAnimal({
"animal": "cat"
});

  

<!DOCTYPE html>
<html>
<head>
<title>Introduction to JavaScript Object Notation</title>
<script>
// example 6-11, modified to alert the variable "myAnimal"
function getTheAnimal(data) {
var myAnimal = data.animal; // will be "cat"
alert(myAnimal);
}
// example 6-12, modified for the src file to load from example10.json
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "example10.json";
document.getElementsByTagName('head')[0].appendChild(script);
</script>
</head>
<body>
<h1>Introduction to JavaScript Object Notation</h1>
</body>
</html>

1.7.0 some example  

{
"total_rows": 2,
"offset": 0,
"rows": [
{
"id": "ddc14efcf71396463f53c0f880001538",
"key": "Barker",
"value": null
},
{
"id": "3636fa3c716f9dd4f7407bd6f700076c",
"key": "Jackson",
"value": null
}
]
}

【EatBook】-NO.1.EatBook.1.JavaData.1.001-《JSON 必知必会-Introduction to JavaScript Object Notation》-的更多相关文章

  1. HTTP Content-type 对照表

    Application Type 文件扩展名 Content-Type(Mime-Type) 描述 . application/x-   .* application/octet-stream 二进制 ...

  2. http Content-type对照表

    http://tools.jb51.net/table/http_content_type Content-Type,内容类型,一般是指网页中存在的Content-Type,用于定 义网络文件的类型和 ...

  3. 初识 MySQL 5.6 新特性、功能

    背景: 之前介绍过 MySQL 5.5 新功能.参数,现在要用MySQL5.6,所以就学习和了解下MySQL5.6新的特性和功能,尽量避免踩坑.在后续的学习过程中文章也会不定时更新. 一:参数默认值的 ...

  4. JSON数据解析(转)

    JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,为Web应用开发提供了一种理想的数据交换格式. 本文将主要介绍在Android ...

  5. JSON数据解析(GSON方式) (转)

    JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,为Web应用开发提供了一种理想的数据交换格式. 在上一篇博文<Andro ...

  6. Android系列---JSON数据解析

    您可以通过点击 右下角 的按钮 来对文章内容作出评价, 也可以通过左下方的 关注按钮 来关注我的博客的最新动态. 如果文章内容对您有帮助, 不要忘记点击右下角的 推荐按钮 来支持一下哦 如果您对文章内 ...

  7. JSON数据解析(转)

    上篇随笔详细介绍了三种解析服务器端传过来的xml数据格式,而对于服务器端来说,返回给客户端的数据格式一般分为html.xml和json这三种格式,那么本篇随笔将讲解一下json这个知识点,包括如何通过 ...

  8. github上所有大于800 star OC框架

    https://github.com/XCGit/awesome-objc-frameworks#awesome-objc-frameworks awesome-objc-frameworks ID ...

  9. 安卓Json介绍(转)。

    1.JSON(JavaScript Object Notation) 定义: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式, ...

随机推荐

  1. 深入web开发之webserver/servlet容器

    可能按照书上的demo,自己就能做个小型网站,但是在并发下是什么情况呢?生成了多少对象?对象的关系又是什么?这些问题都要慢慢弄清楚. ------作为后端工程师,不仅要会增删改查,还要了解servle ...

  2. git diff命令详解

    1 如下命令: [devel@localhost pontus]$ git diff webserver/web_pontus/app_api/v0/urls.py# 显示如下: diff --git ...

  3. js 基础知识总结

    1.switch结构 switch语句部分和case语句部分,都可以使用表达式. switch(1 + 3) { case 2 + 2: f(); break; default: neverhappe ...

  4. ng之自定义指令

    最近开始研究并使用angular,今天就来简单讲讲对于ng中自定义指令的一下使用心得吧! 相信用过ng的人都对ng中的指令有所了解,指令,我将其理解为AngularJS操作HTML element的一 ...

  5. 好用的 Chrome 插件,提升你的学习工作效率

    Google Chrome 应该是大部分人都用的一款浏览器,但却有很少人会注意到它丰富的扩展插件,擅于使用这些插件,能让自己的工作效率大大提高,今天趁着周末休息,就不谈技术伤大家的脑细胞了,给大家分享 ...

  6. windous----操作系统基础

    操作系统基础 服务软件,控制硬件. 一:什么事操作系统 操作系统就是一个协调,管理和控制和计算机硬件资源控制程序.  用户态:运行应用程序,不可以操作硬件(可以获取cpu的指令集的一个子集,该子集不包 ...

  7. 卓越研发之路 MOT技术管理者课堂

    引言:从2018年11月起,在北京.大连.上海.南京.杭州.武汉.成都.西安.深圳.广州等地巡回举办的技术沙龙.活动旨在交流软件研发及互联网技术的实战经验,分享优秀的案例实践,通过平台结识更多友人,挖 ...

  8. got positional argument after named arguments.原因

  9. Python全栈-magedu-2018-笔记11

    第三章 - Python 内置数据结构 简单选择排序 简单选择排序 属于选择排序 两两比较大小,找出极值(极大值或极小值)被放置在固定的位置,这个固定位置一般指的是某一端 结果分为升序和降序排列 降序 ...

  10. HBase实战 | 知乎实时数仓架构演进

    https://mp.weixin.qq.com/s/hx-q13QteNvtXRpNsE5Y0A 作者 | 知乎数据工程团队编辑 | VincentAI 前线导读:“数据智能” (Data Inte ...