json详解
来源:互联网 发布:dw格式化js代码 编辑:程序博客网 时间:2024/05/22 13:31
1 json 对象的访问 ,例如:
<script type="text/javascript">var s = { "section":{"title":"Book-Signing Event","signing":[{"author":{"title":"Mr","name":"Oliver Sacks"},"book":{"title":"A Suitable Boy","prince":"$22.95"}},{"author":{"title":"Mr","name":"Oliver Sacks"},"book":{"title":"The Island of the Color-Blind","prince":"$12.95"}}]}};alert(s.section.title);alert(s.section.signing[0].author.title);alert(s.section.signing[1].book.title);</script>
2 通过特定格式的字符串生成json对象,例如:
String jsonContent = "{'hello':'world','abc':'xyz'}";JSONObject jsonObject = new JSONObject(jsonContent);String str1 = jsonObject.getString("hello");String str2 = jsonObject.getString("abc");System.out.println(str1);System.out.println(str2);
3 通过特定字符串生成json数组
jsonContent = "[{'hello':333, 'abc':false, 'xyz':'test'}, {'hello':555, 'abc':true, 'xyz':'test'}]";JSONArray jsonArray = new JSONArray(jsonContent);for(int i = 0; i < jsonArray.length();i++){JSONObject jsonObject2 = jsonArray.getJSONObject(i);int value1 = jsonObject2.getInt("hello");boolean value2 = jsonObject2.getBoolean("abc");String value3 = jsonObject2.getString("xyz");System.out.println(value1);System.out.println(value2);System.out.println(value3);}
4json的定义
var allOfficeList = {};
赋值 allOfficeList[officeList.options[i].value]=officeList.options[i].text;
遍历:for(var s in allOfficeList){
alert(s + allOfficeList[s]);
}
- JSON 详解
- JSON详解
- JSON详解
- JSON详解
- JSON详解
- JSON详解
- json 详解
- json详解
- JSON详解
- JSON详解
- JSON详解
- json详解
- JSON详解
- JSON详解
- JSON详解
- JSON详解
- json详解
- Json详解
- 仿微博半透明边框
- 写第一个shell脚本,遇到的问题总结整理。
- SAX 解析 XML
- SecureCRT的使用方法和技巧
- 解决超链接访问后hover样式不出现的问题
- json详解
- ArcGIS Engine开发Geodatabase代码(六)——TopologyEdit
- jsp中url重写
- asp.net页面跳转传值的几种方式
- SystemServer systemReady()
- 进程通信-匿名管道
- Linux/Unix环境下计算C程序运行时间
- 2013.1.9
- 屏幕工作区域