在 Java 中读取 JSON 对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1798038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 18:01:40  来源:igfitidea点击:

read a JSON object in java

javajsonjsp

提问by Sadesh Kumar N

How can we read a JSON object in a JSP, Servlet or in any other Java program?

我们如何在 JSP、Servlet 或任何其他 Java 程序中读取 JSON 对象?

回答by BalusC

I would recommend using Gsonfor this. It has the advantage that it supports generics very well and it is also performant. I've posted a Gson#fromJson()example before here: Converting JSON to Java

我建议为此使用Gson。它的优点是它很好地支持泛型并且它也是高性能的。我Gson#fromJson()之前在这里发布过一个例子:Converting JSON to Java

回答by John Paulett

With the jsonlibrary, there is a JAR of it located here. Also, based upon this answer, you might want to look at JSON-lib

对于json库,它的 JAR 位于此处。另外,根据这个答案,你可能想看看JSON-lib

回答by Kevin

JSON.orghas a lot of good information on reading JSON in Java (and other languages as well). They provide a good reference implementation that many other libraries use.

JSON.org有很多关于在 Java(以及其他语言)中读取 JSON 的好信息。它们提供了许多其他库使用的良好参考实现。

回答by Jim Ferrans

Take a look at Hymanson.

看看Hyman逊

回答by Andy

Using a library such as the one described at: http://www.json.org/java/

使用库,例如​​在:http: //www.json.org/java/ 中描述的库

Looking at the description of gson, it certainly looks like it would do the job as well.

查看gson的描述,它当然看起来也能完成这项工作。