when trying to compile a servlet containing JSON code.. (any other servlets compile ok...)
I have json.jar in proper place (I even ran jar tf json.jar command, everything is there..) am running jdk1.5.0_18 and this is specified in JAVA_HOME...
don't know what's up with my tomcat/JSON.. also in JSP I can't run JSON code, get errors like
JSONObject cannot be resolved to a type
even though, again, json.jar is in its proper place, and proper directive is in JSP to import JSON classes...
am on tomcat 5.5
would appreciate suggestions.. thank you..
I'm trying to run example here, http://www.learn-ajax-tutorial.com/Json.cfm#h1.2
he has this line in JSP:
JSONObject objJSON = (JSONObject) JSONValue.parse(strJSON);
get error on JSONValue, where does JSONValuecome from, I don't see JSONValue here, http://www.json.org/javadoc/index-all.html#_J_
he imports org.json.simple, where does he get THAT from, there's no class SIMPLE in org.json.. I changed that directive to just org.json.*, but still get errors...
(I also don't see method parse() here, http://www.json.org/javadoc/index-all.html#_P_) am I on drugs or is he??? ;~)
I get this error: class file has wrong version 50.0, should be 49.0
That sounds like you're using a library that is compiled for use with Java 6, while you're using Java 5. Either recompile the library to work with Java 5 (assuming that's possible, but chances are that it is), or find another library that works with java 5 out of the box, or upgrade your JDK to Java 6.
even though, again, json.jar is in its proper place, and proper directive is in JSP to import JSON classes
By "proper place" you mean your web app's WEB-INF/lib directory, right? Post the JSP directive.
where does JSONValuecome from, I don't see JSONValue here ... he imports org.json.simple, where does he get THAT from, there's no class SIMPLE in org.json..
The footnote on that page tells you where to get the required files.
But in general, note this paragraph under "JSON parsers -> on the server-side", which I take to mean that you should adapt the code to whatever JSON library you happen to use:
Decode the incoming JSON string and convert the result to an object using a JSON parser for the language of your choice. At http://www.json.org, you'll find JSON parsers for many modern programming languages. The methods available depend upon which parser you are using. See the parser's documentation for details.
oh man.. I got src code, compiled all classes, put in json.jar put json.jar in <appName>WEB-INF/lib.. but get EXACT SAME error I was getting before..
JSONObject cannot be resolved to a type
again, this is for example here, http://www.learn-ajax-tutorial.com/Json.cfm#h1.2
(and, again, I changed the import of org.json.simple.* to just org.json.* since org.json.simple.* doesn't make sense to me, but in both cases I get same error...)
When are you getting this, during compilation? Is a stack trace provided? Can you please show this? (use code tags)
As far as the import goes, what is the fully-qualified package name of the objects you are referencing in your source file? That will tell you what you want for import statements. For example if the class you're referencing is com.company.product.MyClass, then you can use the following import: If you really want to, you can use glob characters in the import, so instead you could use the following:
If the class you're trying to reference needs an import which you don't have, you'll get a different error, so I don't think that's what's happening here (although your last posted error message was pretty vague, so I'm not sure).
(it may take a wink or two till buttons react, not sure why... at any rate get error on both buttons...)
JSP code for ReceiveJSON.jsp is exactly what it appears here:
EXCEPT I changed this:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.net.*,org.json.simple.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.net.*,org.json.*"%>
org.json.simple.* didn't make sense to me, as I don't see a package "simple" here,
in WEB-INF/lib/ I have json.jar, compiled by myself (from src code gotten from here, www.json.org/java/index.html) on sdk 1.5...
( & tomcat is 5.5....)