java封装json串示例_Java JSON示例

java封装json串示例Welcome to the Java JSON Example Tutorial. JSON (JavaScript Object Notation) is text-based lightweight technology for generating human readable formatted data. JSON represent object data ...
摘要由CSDN通过智能技术生成

java封装json串示例

Welcome to the Java JSON Example Tutorial. JSON (JavaScript Object Notation) is text-based lightweight technology for generating human readable formatted data. JSON represent object data in the form of key-value pairs. We can have nested JSON objects too and it provides an easy way to represent arrays also.

欢迎使用Java JSON示例教程。 JSON (JavaScript对象表示法)是一种基于文本的轻量级技术,用于生成人类可读的格式化数据。 JSON以键值对的形式表示对象数据。 我们也可以嵌套JSON对象,它还提供了一种表示数组的简便方法。

Java JSON (Java JSON)

JSON is widely used in web applications or as server response because it’s lightweight and more compact than XML. JSON objects are easy to read and write and most of the technologies provide support for JSON objects. That’s why JSON in Java web services are very popular.

JSON被广泛用于Web应用程序或服务器响应,因为它比XML轻巧且紧凑。 JSON对象易于读写,并且大多数技术都提供对JSON对象的支持。 这就是Java Web服务中JSON非常流行的原因。

JSR353 finally made into Java EE 7 and it’s the Java JSON processing API. jsonp is the reference implementation for Java JSON Processing API. We can use this in maven project by adding following dependency.

JSR353最终被制成Java EE 7,它是Java JSON处理API。 jsonp是Java JSON处理API的参考实现。 我们可以在maven项目中通过添加以下依赖项来使用它。

<dependency>
	<groupId>org.glassfish</groupId>
  	<artifactId>javax.json</artifactId>
  	<version>1.0.2</version>
</dependency>

If you are using GlassFish 4.0 then you can keep the scope as provided because it’s already included in the server.

如果您使用的是GlassFish 4.0,则可以保留提供的范围,因为它已包含在服务器中。

JSON API provides two ways for JSON processing:

JSON API提供了两种JSON处理方式:

  1. Object Model API – It’s similar to DOM Parser and good for small objects.

    对象模型API –与DOM分析器相似,适用于小型对象。
  2. Streaming API – It’s similar to StaX Parser and good for large objects where you don’t want to keep whole object in memory.

    流API –与StaX Parser相似, 适用于不想将整个对象保留在内存中的大型对象。

Some important interfaces of Java JSON API are:

Java JSON API的一些重要接口是:

  1. javax.json.JsonReader: We can use this to read JSON object or an array to JsonObject. We can get JsonReader from Json class or JsonReaderFactory.

    javax.json.JsonReader :我们可以使用它来读取JSON对象或JsonObject的数组。 我们可以从Json类或JsonReaderFactory获取JsonReader。
  2. javax.json.JsonWriter: We can use this to write JSON object to output stream.

    javax.json.JsonWriter :我们可以使用它编写JSON对象以输出流。
  3. javax.json.stream.JsonParser: This works as a pull parser and provide streaming support for reading JSON objects.

    javax.json.stream.JsonParser :这用作拉解析器,并提供流支持以读取JSON对象。
  4. javax.json.stream.JsonGenerator: We can use this to write JSON object to output source in streaming way.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值