JavaScript JSON 数据处理
在JavaScript 也自带了 JSON 格式的处理
<!doctype html>
<html>
<script>
var test_json_str =
{
"name" : "chen",
"age" : 18,
"sex" : "man"
}
// json obj ---> json str JSON 类转换为字符串
str_json1 = JSON.stringify(test_json_str);
document.write("str_json1:<br>");
document.write(str_json1);
document.write("<br>");
document.write(test_json_str);
document.write("<br>");
document.write("<br>");
// json str ---> json obj 字符串转换为类
var obj = JSON.parse(str_json1);
document.write("old mesage: <br>");
document.write(obj["name"]);
document.write("<br>");
document.write(obj["age"]);
document.write("<br>");
document.write(obj["sex"]);
document.write("<br>");
//document.write(obj);
// change obj 修该 JSON 类的属性
obj["name"] = "chenfulin";
obj["age"] = 100;
obj["sex"] = "manman";
document.write("<br>");
document.write("new json obj: <br>");
document.write(obj["name"]);
document.write("<br>");
document.write(obj["age"]);
document.write("<br>");
document.write(obj["sex"]);
document.write("<br>");
document.write("<br>");
document.write("new json string: <br>");
// json obj ---> json str JSON 类转换为字符串
str_json1 = JSON.stringify(obj);
document.write(str_json1);
</script>
</html>
后有如下显示:
str_json1:
{"name":"chen","age":18,"sex":"man"} // 这是显示 转换后的字符串
[object Object] // 直接写这个 obj 会显示这个
old mesage: // 显示老的 JSON 类的内容
chen
18
man
new json obj: // 修改 JSON 类
chenfulin
100
manman
new json string:
{"name":"chenfulin","age":100,"sex":"manman"} //再 转换成字符串输出
JavaScript JSON 数据处理的更多相关文章
- 【多端应用开发系列1.1.1 —— Android:使用新浪API V2】服务器Json数据处理——Json数据概述
[前白] 一些基础的东西本系列中就不再详述了,争取尽量写些必不可少的技术要点. 由于本系列把Web Service 构建放到了第二部分,Android项目就采用新浪微博API v2作为服务器端. [原 ...
- JavaScript Json对象和Json对象字符串的关系 jsonObj<->JsonString
JavaScript Json对象和Json对象字符串的关系 jsonObj<->JsonString 如下示例: 直接写的a1就是一个Json对象,a2 就是一个Json对象字符串; 通 ...
- iOS开发——数据解析Swift篇&简单json数据处理
简单json数据处理 //loadWeather var url = NSURL(string: "http://www.weather.com.cn/adat/sk/101240701.h ...
- Spark SQL JSON数据处理
背景 这一篇可以说是“Hive JSON数据处理的一点探索”的兄弟篇. 平台为了加速即席查询的分析效率,在我们的Hadoop集群上安装部署了Spark Server,并且与我们的Hive数据仓 ...
- JavaScript JSON timer(计时器) AJAX HTTP请求 同源策略 跨域请求
JSON 介绍 1. JSON: JavaScript Object Notation 是一种轻量级的数据交换格式. 它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是 ...
- python接口自动化(十九)--Json 数据处理---实战(详解)
简介 上一篇说了关于json数据处理,是为了断言方便,这篇就带各位小伙伴实战一下.首先捋一下思路,然后根据思路一步一步的去实现和实战,不要一开始就盲目的动手和无头苍蝇一样到处乱撞,撞得头破血流后而放弃 ...
- JavaScript -- JSON.parse 函数 和 JSON.stringify 函数
JavaScript -- JSON.parse 函数 和 JSON.stringify 函数 1. JSON.parse 函数: 使用 JSON.parse 可将 JSON 字符串转换成对象. &l ...
- 细读 php json数据和JavaScript json数据
关于JSON的优点: 1.基于纯文本,跨平台传递极其简单: 2.Javascript原生支持,后台语言几乎全部支持: 3.轻量级数据格式,占用字符数量极少,特别适合互联网传递: 4.可读性较强 5.容 ...
- JavaScript JSON AJAX 同源策略 跨域请求
网页和Ajax和跨域的关系 1 Ajax使网页可以动态地.异步地的与服务器进行数据交互,可以让网页局部地与服务器进行数据交互 2 Ajax强调的是异步,但是会碰到跨域的问题. 3 而有很多技术可以解决 ...
随机推荐
- Android 自定义漂亮的圆形进度条
公司有这样一个需求,实现这个圆弧进度条 所以,现在就将它抽取出来分享 如果需要是圆帽的就将,下面这句代码放开即可 mRingPaint.setStrokeCap(Paint.Cap.ROUND);// ...
- JAX-RS annotations
@Path("resource_path"):The @Path annotation defines the path to the base URL or resource_p ...
- UnicodeDecodeError: 'utf-8' codec can't decode byte
for line in open('u.item'): #read each line whenever I run this code it gives the following error: U ...
- 携程的配置中心(阿波罗apollo)
https://github.com/ctripcorp/apollo https://pan.baidu.com/s/1dFEGMIX#list/path=%2Fmeetup%20ppt%2F040 ...
- mysql分享一:运维角度浅谈MySQL数据库优化
转于:http://lizhenliang.blog.51cto.com/7876557/1657465 1.数据库表设计要合理避免慢查询.低效的查询语句.没有适当建立索引.数据库堵塞(死锁)等 2. ...
- 微服务,ApiGateway 与 Kong
一. 微服务 二. Api Gateway 三. Kong 的使用 一. 微服务 对于一些传统的 大型项目,传统的方式会有一些缺陷,比如说 新人熟悉系统成本高(因为整个系统作为一个整体,彼此会有一定的 ...
- Android基础知识之String类使用详解
原文:http://android.eoe.cn/topic/android_sdk 字符串资源为你的应用程序提供了可以选择的文本样式和格式的文本.这里有三种类型的资源可以为你的应用程序提供字符串. ...
- android源码编译-Mac 10.11 xcode5.1.1
第一步: 参考官网:创建一个dmg,大小80g,这个要尽量大一点,40g感觉不够用:http://source.android.com/source/initializing.html 第二步:下载a ...
- HTML5学习笔记(五):CSS基础
CSS 指层叠样式表 (Cascading Style Sheets),在网页中用来定义网页的元素如何进行显示. CSS 对大小写不敏感.不过存在一个例外:如果涉及到与 HTML 文档一起工作的话,c ...
- FFmpeg(2)-avformat_open_input()函数详解并示例打开mp4文件
一. 解封装 pts 是显示的时间 dts是解码的时间, 这个时间是用来做同步. av_register_all(), 注册所有的格式.包括解封装格式和加封装格式. avformat_network_ ...