首页 > 网站 > WEB开发 > 正文

JavaScript高级程序设计之JSON

2024-04-27 14:22:58
字体:
来源:转载
供稿:网友

javaScript高级程序设计之JSON

IE8以下请求助神之Douglas Crockford:https://github.com/douglascrockford/json-js

JSON是一种格式化的字符串,特别适合在网络上传输,由Douglas Crockford发明。

JSON语法可以表示三种类型的值:

简单值:字符串、数值、布尔值和null

对象

数组

特别说明:JSON属性名必须加双引号;而Javascript对象的属性如果是合法的标示符则不用加双引号。

// 一个javascript对象var conference = {      Conference: "Future Marketing",       Address: "Shanghai",      Members:[          {              name: "Bob",              age: 32,              company: "Oracle",              enginner: true          },          {              name: "John",              age: 30,              compancy: "Google",              enginner: false          }      ]};var jsontext = JSON.stringify(conference, ["Conference", "Address"]);// string: {"Conference":"Future Marketing","Address":"Shanghai"}var anotherObj = JSON.parse(jsontext, function (key, value) {    if (key === "Conference") {        return "a conference";    } else {        return value;    }});// object: { Conference="a conference", Address="Shanghai"}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表