JSON 通常用于与服务端交换数据。

在接收服务器数据时一般是字符串。

我们可以使用 JSON.parse() 方法将数据转换为 JavaScript 对象。

语法

JSON.parse(text[, reviver])

参数说明:

  • text:必需, 一个有效的 JSON 字符串。
  • reviver: 可选,一个转换结果的函数, 将为对象的每个成员调用此函数。

JSON 解析实例

例如我们从服务器接收了以下数据:

{ "name":"runoob", "alexa":10000, "site":"www.runoob.com" }

我们使用 JSON.parse() 方法处理以上数据,将其转换为 JavaScript 对象:

var obj = JSON.parse('{ "name":"runoob", "alexa":10000, "site":"www.runoob.com" }');

解析完成后,我们就可以在网页上使用 JSON 数据了:

例如:

<p id="demo"></p>

<script>
var obj = JSON.parse('{ "name":"runoob", "alexa":10000, "site":"www.runoob.com" }');
document.getElementById("demo").innerHTML = obj.name + ":" + obj.site;
</script>

从服务端接收 JSON 数据

我们可以使用 AJAX 从服务器请求 JSON 数据,并解析为 JavaScript 对象。

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myObj = JSON.parse(this.responseText);
document.getElementById("demo").innerHTML = myObj.name;
}
};
xmlhttp.open("GET", "/try/ajax/json_demo.txt", true);
xmlhttp.send();

从服务端接收数组的 JSON 数据

如果从服务端接收的是数组的 JSON 数据,则 JSON.parse 会将其转换为 JavaScript 数组:

异常

解析数据

JSON 不能存储 Date 对象。

如果你需要存储 Date 对象,需要将其转换为字符串。

之后再将字符串转换为 Date 对象。

l例如:

var text = '{ "name":"Runoob", "initDate":"2013-12-14", "site":"www.runoob.com"}';
var obj = JSON.parse(text);
obj.initDate = new Date(obj.initDate); document.getElementById("demo").innerHTML = obj.name + "创建日期: " + obj.initDate;

我们可以启用 JSON.parse 的第二个参数 reviver,一个转换结果的函数,对象的每个成员调用此函数。

var text = '{ "name":"Runoob", "initDate":"2013-12-14", "site":"www.runoob.com"}';
var obj = JSON.parse(text, function (key, value) {
if (key == "initDate") {
return new Date(value);
} else {
return value;
}}); document.getElementById("demo").innerHTML = obj.name + "创建日期:" + obj.initDate;

解析函数

JSON 不允许包含函数,但你可以将函数作为字符串存储,之后再将字符串转换为函数。

var text = '{ "name":"Runoob", "alexa":"function () {return 10000;}", "site":"www.runoob.com"}';
var obj = JSON.parse(text);
obj.alexa = eval("(" + obj.alexa + ")"); document.getElementById("demo").innerHTML = obj.name + " Alexa 排名:" + obj.alexa();

浏览器支持

主流浏览器都支持 JSON.parse() 函数:

  • Firefox 3.5
  • Internet Explorer 8
  • Chrome
  • Opera 10
  • Safari 4

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAikAAACMCAIAAAA2v649AAAfJklEQVR4nO2dPW/jSLaG68dIoZj0vxAUOlE3Y8cCpKQ7FW6LQaMTf0CJAo0FQ2i0PCvAMCYYzxoQHAjCYMw77aANLJzu5loM5jLoG5As1qkvFimJlu33QWPXIquKh8XieeucKmnYDwAAAKBa2FMbAAAA4NUB7QEAAFA10B4AAABVA+0BAABQNdAeAAAAVQPtAQAAUDXQnmfIvPfm4CjMOwQAAHvLq9aeee+Nhd6cFwyPDuJP3MXPe/H58OhALJgcceTgKPzxIzw60KvGvPdGatpg9cHRXL0mtV7XUL5chUcHb5wlzbE5yZB5z+kKxk4qS3h0oF5X21HSfWkrqlV6c+NIILVNvWZ4Zjk3IFuh6W1TnWKlXx2ku9OOkR+S8mb2jnRDwPpcXxE70B7lrXAYw+F87vxKuFPu5YldBq2Y+r6kRd5wGZ+oWDXvaQek9taTg+RcYoTi2u3Smv86zHtv3hwc5LtaUt5YVrWmN1e9c1o/3/aN3+D44rwZk/Ua7bFe2lFN9a27XyZXe9SWbW0WK13KoNLQsVD8uTv6kPncXIZ2BteecK6bndl6buuTqGfM7rXHbT68owdSUH0kd0RP9VLRmadRkDqzdbmYzibDMctMNBvgPCjT1ykZ93AlM7y5rsLGbUz+nPf4RVO7xBswGCe9skX9onRbDmRXK6I9hlnEJoaY2rO9NPphqT4xPn8qUNp6Q9t/i+UJVaFQvAB2fZLGgDzzowbRES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BqoD0AAACqJtGef//73/8CAAAAKiHRHgAAAKAyoD0AAACqBtoDAACgaqA9AAAAqgbaAwAAoGr+H+O44iaS/JM2AAAAAElFTkSuQmCC" alt="" />

JSON.parse()——json字符串转JS的更多相关文章

  1. 实现深拷贝还在用JSON.parse(JSON.stringify(obj))?带你用JS实现一个完整版深拷贝函数

    使用JavaScript实现深拷贝 1.JSON序列化实现深拷贝 在JS中,想要对某一个对象(引用类型)进行一次简单的深拷贝,可以使用JSON提供给我们的两个方法. JSON.stringfy():可 ...

  2. JSON.parse(JSON.stringify(obj))

    JSON.parse(JSON.stringify(obj)实现数组的深拷贝 利用JSON.stringify 将js对象序列化(JSON字符串),再使用JSON.parse来反序列化(还原)js对象

  3. JSON.parse(JSON.stringify()) 实现对对象的深拷贝

    JSON.parse(JSON.stringify(obj))我们一般用来深拷贝,其过程说白了 就是利用JSON.stringify 将js对象序列化(JSON字符串),再使用JSON.parse来反 ...

  4. 关于JSON.parse(JSON.stringify(obj))实现深拷贝应该注意的坑

    JSON.parse(JSON.stringify(obj))我们一般用来深拷贝,其过程说白了 就是利用JSON.stringify 将js对象序列化(JSON字符串),再使用JSON.parse来反 ...

  5. JSON.parse() JSON.stringify() eval() jQuery.parseJSON() 的区别

    http://www.jb51.net/article/81880.htm    :   jQuery.parseJSON(jsonString) : 将格式完好的JSON字符串转为与之对应的Java ...

  6. 使用JSON.parse(),JSON.stringify()实现对对象的深拷贝

    根据不包含引用对象的普通数组深拷贝得到启发,不拷贝引用对象,拷贝一个字符串会新辟一个新的存储地址,这样就切断了引用对象的指针联系. 测试例子: var test={ a:"ss", ...

  7. JSON.parse JSON.stringify

    JSON.stringify() undefined 值.函数或者XML值会被忽略 数组当中含有 undefined值,函数或XML值,该数组中的这些值将会被当成 null 正则对象会被转成空对象 J ...

  8. 【Immutable】拷贝与JSON.parse(JSON.stringify()),深度比较相等与underscore.isEqual(),性能比较

    样本:1MB的JSON文件,引入后生成500份的一个数组: 结果如下: 拷贝性能: JSON.parse(JSON.stringify()) 的方法:2523.55517578125ms immuta ...

  9. this.treeData = JSON.parse(JSON.stringify(this.d)) 树的序列化反序列化

    this.treeData = JSON.parse(JSON.stringify(this.d))

  10. JSON.parse(JSON.stringify()) 实现对对象的深度拷贝,从而互不影响

    JSON.parse(JSON.stringify({"key": "value"})) 根据不包含引用对象的普通数组深拷贝得到启发,不拷贝引用对象,拷贝一个字 ...

随机推荐

  1. fiddler启动报错Unable to bind to port [8888],ErrorCode:10106

    启动运行fiddler 报错,提示Unable to bind to port [8888],ErrorCode:10106 解决方式: 使用Fiddler或其他类似的监听工具出现这种错误时, Una ...

  2. 第117天:Ajax实现省市区三级联动

    Ajax实现省市区三级联动 思路: (1)首先获取省份信息 (2)发起Ajax请求,注意dataType中的T大写 (3)封装回调函数,回调函数success中用$.each循环每一条数据,动态创建o ...

  3. click()、bind()、live()和delegate()方法

    我之前使用click()比较多,又来因为网页内容需要前端生成用了live().有的时候使用click()和bind()分不清楚该怎么试用.查了很多资料.测试了很多次,自己明白了. 总结如下:代码注释很 ...

  4. Authenticator及AuthenticationStrategy

    Authenticator的职责是验证用户帐号,是Shiro API中身份验证核心的入口点: 如果验证成功,将返回AuthenticationInfo 验证信息:此信息中包含了身份及凭证:如果验证失败 ...

  5. C++解析(12):初始化列表与对象构造顺序、析构顺序

    0.目录 1.类成员的初始化 2.类中的const成员 3.对象的构造顺序 3.1 局部对象的构造顺序 3.2 堆对象的构造顺序 3.3 全局对象的构造顺序 4.对象的析构顺序 5.小结 1.类成员的 ...

  6. QoS专题-第1期-QoS理论篇

    QoS理论篇 1      QoS的产生 随着网络技术的飞速发展,IP网络已经从当初的单一数据网络向集成数据.语音.视频.游戏的多业务网络转变.网络中所承载的数据呈几何级倍数增长,而且这些业务对网络带 ...

  7. Django模板语言循环字典

    1. 对于字典,可以有下列用法: {% for row in user_dict.keys %} {% for row in user_dict.values %} {% for row in use ...

  8. 【BZOJ3437】小P的牧场(动态规划,斜率优化)

    [BZOJ3437]小P的牧场(动态规划,斜率优化) 题面 BZOJ 题解 考虑暴力\(dp\),设\(f[i]\)表示强制在\(i\)处建立控制站的并控制\([1..i]\)的最小代价. 很显然,枚 ...

  9. JAVA本地TXT文件解决中文乱码问题

    import java.io.*; public class ReadFile { public static void main(String[] args) { try { File file = ...

  10. 【Django实例】博客1

    (上一篇) 一.概述 Blog是一个博客应用. dbe工程的目录结构,参考<序言>的最后部分.blog应用位于/home/russellluo/Django/dbe/dbe/blog目录下 ...