JSON的起源
除XML数据传输格式外,还有一种相对来说使用很多的数据传输格式
甚至某些场合使用的比XML还要多,这种数据传输格式就是所谓的JSON
JSON(JavaScript Object Notation)的官网是http://www.json.org
他的创建者是雅虎的主架构师,也是YUI(Yahoo User Interface)框架的架构师
他就是道格拉斯(Douglas Crockford),他是在雅虎工作期间发明的JSON数据传输格式
JSON的好处
①JSON相对于XML来说,它读起来更加简单方便
②JSON更加简洁,传输量更加少。因为它使用的字符明显少很多
对于大量数据的情况来说,使用XML显然比JSON要传输更多的数据
所以使用JSON可以在一定程度上降低网络负载
③若使用JSON仅表示一个对象的话,直接{id: 1, name: zhangsan}即可
④JSON的本质非常简单,它的基本想法就是通过name-value的形式描述信息
类似于Java集合的Map,下面分别举例通过XML和JSON描述2个用户的信息
[{id: 1, name: zhangsan}, {id: 2, name: lisi}]
<users>
<user>
<id>1</id>
<name>zhangsan</name>
</user>
<user>
<id>2</id>
<name>lisi</name>
</user>
</users>
下面是JSON与Struts2集成的演示,其中前台页面使用了JQuery实现异步请求
首先是web.xml文件
然后是jsonTest.jsp页面
接着是struts.xml文件
然后是POJO类
最后是核心的GetJsonAction类
分享到:
相关推荐
what is seen and what is not seen 一部很不错的书。
ChatGPT研究资料,What Is ChatGPT Doing ... and Why Does It Work (Stephen Wolfram) (Z-Library)
JavaScript and JSON Essentials is a step-by-step guide that will introduce you to JSON and help you understand how the lightweight JSON data format can be used in different ways either to store data ...
what is seen and what is not seen.zip
没有人预料到这一点——甚至包括它的创造者:ChatGPT作为一种能够以令人信服的人类水平进行写作的AI已经出现在舞台上。但是它真正的工作原理是什么?其“AI大脑”内部发生了什么?在这本短篇书籍中,杰出科学家和...
It addresses the question of what is geometry, how are its various facets connected with each other, and how are geometry and group theory involved in physics. Besides Lie and Klein, the names of ...
What is I and Q Date
What is Nucleus C++ FILE? Nucleus C++ FILE is a C++ class interface into Nucleus FILE, a FAT16/FAT32 TM compatible file system specifically designed to work in embedded systems in conjunction with the...
What Is Computer Science
What is Middleware.pdf E文的
This is a classic explanation on "what is a quant". Very good reading for the "want-to-be".
What is Data Mining.pdf is Data Mining document for SA.
优秀的数学科普著作,原版
• What is and how to use the Object Definition Syntax supported in JSON • What comprises a JSON content production workflow • What are the concepts and principles behind the JSON Object ...
What is mathematics An Elementary Approach to Ideas and Methods
what is social media-book
21. What is Jensen’s Inequality and what is its role in finance? 97 22. What is Itô’s lemma? 100 23. Why does risk-neutral valuation work? 103 24. What is Girsanov’s theorem and why is it ...
1. What is the IP address and TCP port number used by the client computer (source) that is transferring the file to gaia.cs.umass.edu? To answer this question, it’s probably easiest to select an ...
What is a Matroid, James Oxley 精简介扫什么是拟阵(独立性泛化),拟阵的多个等价定义,拟阵的域表示,可图拟阵等等。
WHAT IS A MATROID? JAMES OXLEY Abstract. Matroids were introduced by Whitney in 1935 to try to capture abstractly the essence of dependence. Whitney’s definition embraces a surprising diversity of ...