Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

compilation problem with JSON

807580Dec 17 2009 — edited Dec 17 2009
Hi,

I just created a class service.java. It is as follows
import org.json.simple.JSONObject;

public class service {
		JSONObject obj=new JSONObject();         //line 1
		obj.put("name","foo");                               //line 2
		obj.put("num",new Integer(100));                //line 3
		obj.put("balance",new Double(1000.21));    //line 4
		obj.put("is_vip",new Boolean(true));           //line 5
		obj.put("nickname",null);                          //line 6
		out.print(obj);                                           //line 7
		out.flush();                                               //line 8
}
I am getting a compilation error stating
"Syntax error on token(s), misplaced construct(s)" on line 1,
"Syntax error on tokens, delete these tokens" on line 1,
"Syntax error on token "flush", Identifier expected after this token" on line 8,
"Syntax error on token "obj", VariableDeclaratorId expected after this token" on line 7,
"Syntax error on tokens, AnnotationName expected instead" on line 3.
"Syntax error, insert "Type VariableDeclaratorId" to complete FormalParameterList" on line 3.

Please help.


Regards,
Anas
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 14 2010
Added on Dec 17 2009
3 comments
983 views