如何解决"org.json.simple.JSONObject无法解析"?

编程入门 行业动态 更新时间:2024-10-21 05:58:26
本文介绍了如何解决"org.json.simple.JSONObject无法解析"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我尝试通过Tomcat打开jsp时,收到以下消息:

When I try to open my jsp through Tomcat, I receive the following messages:

无法解析org.json.simple.JSONObject类型.它是从所需的.class文件中间接引用的.

The type org.json.simple.JSONObject cannot be resolved. It is indirectly referenced from required .class files.

Ejercicio类型的getJSONObject()方法引用缺少的JSONObject类型.

The method getJSONObject() from the type Ejercicio refers to the missing type JSONObject.

我有一个像这样的java类:

I have a java class that goes like this:

package E; import org.json.simple.*; import javax.json.*; import org.json.*; public class Ejercicio { public int a; public String b; public Ejercicio (int a, String b) { this.a=a; this.b=b; } public JSONObject getJSONObject() { JSONObject obj = new JSONObject(); obj.put("a", a); obj.put("b", b); return obj; } }

我的jsp如下:

<%@page import="java.io.*" %> <%@page import="java.util.*"%> <%@page import="E.Ejercicio"%> <%@page import="javax.json.*"%> <%@page import="org.json.simple.*"%> <%@page import="org.json.*"%> <%@page import="net.sf.json.*" %> <% ArrayList<Ejercicio> miArray = new ArrayList<Ejercicio>(); miArray.add(new Ejercicio (1,"Hola")); miArray.add(new Ejercicio (2,"Caracola")); miArray.add(new Ejercicio (3,"Perola")); for (Ejercicio temp:miArray) { out.println("<p>"+temp.b+"</p>"); } JSONArray jsonArray = new JSONArray(); for (int i=0; i < miArray.size(); i++) { jsonArray.put(miArray.get(i).getJSONObject()); } %>

我在WEB-INF的lib文件夹和Tomcat lib中都添加了很多jar,试图解决没有结果的问题(commons-beanutils-1.8.1,commons-collections-3.2.1,commons- lang-2.5,commons-logging-1.1.1,ezmorph-1.0.6,java-json,javax.json-1.0,json-lib-2.4-jdk15,json-rpc-1.0,json-simple-1.1.1-来源,org.json).

I have added a lot of jars to both the lib folder inside WEB-INF and the Tomcat lib trying to solve the problem with no results (commons-beanutils-1.8.1, commons-collections-3.2.1, commons-lang-2.5, commons-logging-1.1.1, ezmorph-1.0.6, java-json, javax.json-1.0, json-lib-2.4-jdk15, json-rpc-1.0, json-simple-1.1.1-sources, org.json).

当我编译Java类时,我得到了某些输入文件使用未经检查或不安全的操作".信息.可能与jps无法编译有关吗?

When I compiled the java class I got the "Some input files use unchecked or unsafe operations" message. Could this be related to the jps not compiling?

推荐答案

首先,您的项目中不需要json-simple.jar. 因此,删除import org.json.simple.*

Firstly, you don't need the json-simple.jar in your project. Therefore remove the import org.json.simple.*

第二,最佳实践是仅从jar中导入所需的类.因此,您可以将

Secondly, the best practice is to import only the required classes from your jar.Therefore you can replace import org.json.*; by

import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONString;

更多推荐

如何解决"org.json.simple.JSONObject无法解析"?

本文发布于:2023-10-25 08:43:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1526469.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何解决   quot   org   JSONObject   simple

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!