深入理解JSON数据源格式
时间:2024-05-10 14:06:09
JSON [ JavaScript Object Notation ]:JavaScript 对象表示法。
它是一种轻量级的数据交换格式。
JSON 在很多场合下作为数据格式比XML 要更加方便。
JSON 的数据由对象、数组和元素等格式组成。每种格式都可以包含合法的JavaScript 数据类型。
在JavaScript 中,可以通过eval( ) 方法将字符串直接转化为JSON 格式。
JSON 数据源格式如下:
示例一:
{
"tablename":"表名",
"rows":[{"列1":"值1"},{"列2":"值2"}.....{"列n":"值n"}]
}
示例二:
/* 与 JSON 等价的代码
var obj = new Object();
obj.createPerson = function(_name,_age){
this.name = _name;
this.age = _age;
}
obj.getAge = function(){
return this.age;
}
*/
var person = {
"createPerson": function(_name,_age){
this.name = _name;
this.age = _age;
},
"getAge": function(){
return this.age;
}
};
person.createPerson("xugang",20);
var p = person.getAge();
alert(p);
示例三:通过eval( ) 方法将字符串直接转化为JSON 并获得元素的值。
<script type="text/javascript">
<!--
window.onload = function(){
var json_text = "{ 'book':{'name':'JAVA编程','author':['Liu','Xu']},'num':222}";
//使用eval()将字符串转换为对象
var json_obj = eval("("+ json_text +")");
//访问 book-name
document.write(json_obj.book.name);
//访问 book-author-Xu
document.write(json_obj.book.author[1]);
}
//-->
</script>
附:在JQuery 中提供了 $.getJSON( ) 方法,可以很快捷地访问到服务器端返回的JSON 数据。
标签:JSON格式
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
查询mysql中执行效率低的sql语句的方法
2024-01-24 09:58:36
详解Python如何制作自动发送微信的程序
2021-06-04 13:24:53
![](https://img.aspxhome.com/file/2023/8/99558_0s.png)
SQL Server中使用Linkserver连接Oracle的方法
2024-01-23 07:35:00
![](https://img.aspxhome.com/file/2023/9/113569_0s.png)
python人工智能tensorflow函数tf.layers.dense使用方法
2022-03-09 21:52:34
python中的queue队列类型及函数用法
2023-09-04 21:04:01
如何利用Python识别图片中的文字详解
2021-02-07 21:05:30
![](https://img.aspxhome.com/file/2023/8/121778_0s.png)
Oracle数据库按时间进行分组统计数据的方法
2023-07-14 13:52:56
深入了解和应用Python 装饰器 @decorator
2024-01-02 09:20:05
![](https://img.aspxhome.com/file/2023/2/72152_0s.jpg)
Python首次安装后运行报错(0xc000007b)的解决方法
2023-12-15 12:33:49
![](https://img.aspxhome.com/file/2023/7/103157_0s.png)
深入浅出Golang中的sync.Pool
2024-02-11 12:59:34
![](https://img.aspxhome.com/file/2023/8/112208_0s.png)
基于Python-Pycharm实现的猴子摘桃小游戏(源代码)
2023-07-07 06:31:22
![](https://img.aspxhome.com/file/2023/5/60705_0s.png)
python随机数分布random测试
2022-01-05 00:41:17
![](https://img.aspxhome.com/file/2023/9/105609_0s.jpg)
多语言网站开发 不完全技术分析
2008-02-18 12:52:00
Python快速生成随机密码超简单实现
2022-08-07 19:26:09
![](https://img.aspxhome.com/file/2023/3/77923_0s.png)
AJAX概述
2007-11-03 13:41:00
Python面向对象编程(三)
2021-10-09 18:28:06
Win下PyInstaller 安装和使用教程
2022-08-14 21:29:53
![](https://img.aspxhome.com/file/2023/1/94151_0s.png)
python爬虫爬取淘宝商品信息
2023-07-04 10:33:24
![](https://img.aspxhome.com/file/2023/9/75239_0s.jpg)
解决PyTorch与CUDA版本不匹配的问题
2023-12-20 14:41:15
![](https://img.aspxhome.com/file/2023/6/92346_0s.jpg)
Python3爬虫带上cookie的实例代码
2021-11-10 18:06:58