[json-lib-user] JSON Lib Issue
Brought to you by:
aalmiray
From: Janardhanan V. <jve...@gm...> - 2006-12-06 23:30:00
|
Hi, I am trying to use JSON in our current project and when I try to run the following program I am getting the following error given below. The sample code is also given below. When the property is of type Object then I am getting this error. When I change the type from Object to String it works fine. But I need to the type be Object for our requirement. Exception in thread "main" net.sf.json.JSONException: A JSONObject text must begin with '{' at character 1 of json at net.sf.json.util.JSONTokener.syntaxError(JSONTokener.java:502) at net.sf.json.JSONObject.<init>(JSONObject.java:660) at net.sf.json.JSONObject.<init>(JSONObject.java:839) at net.sf.json.JSONObject.fromString(JSONObject.java:260) at net.sf.json.JSONObject.fromObject(JSONObject.java:239) at net.sf.json.JSONObject.setValue(JSONObject.java:533) at net.sf.json.JSONObject.fromBean(JSONObject.java:162) at net.sf.json.JSONObject.fromObject(JSONObject.java:246) at net.sf.json.JSONArray.fromObject(JSONArray.java:199) at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:63) at com.debug.JSONIssue.constructJSONFromObject(JSONIssue.java:15) at com.debug.JSONIssue.main(JSONIssue.java:11) package com.debug; import net.sf.json.JSON; import net.sf.json.JSONSerializer; public class JSONIssue { public static void main(String args[]) throws Exception{ IssueObject o = new IssueObject(); o.setValue("json"); System.out.println(constructJSONFromObject(o)); } private static JSON constructJSONFromObject(IssueObject o) throws Exception { return JSONSerializer.toJSON(o); } } package com.debug; public class IssueObject { private Object value; public IssueObject(){ } public Object getValue() { return value; } public void setValue(Object value) { this.value = value; } } Regards, Jana |