我试图在servlet中获取一些变量,这些变量都通过ajax调用传递。但我得到构造函数JSONobject(字符串)是未定义的错误。我也导入了必需的lib。请帮忙
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.json.*;
public class insertserv extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
System.out.println("I am inside insert");
String json = "";
BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream()));
if (br != null) {
json = br.readLine();
}
System.out.println(json);
JSONObject wholedata= new JSONObject(json);
response.setContentType("application/json");
PrintWriter out= response.getWriter();
}
}

答案 0 :(得分:3)
删除了org.json.simple.JSONObject;并使用org.json.JSONObject更新;它解决了我的问题