aspose file tools*
The moose likes Other Open Source Projects and the fly likes JSON problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "JSON problem" Watch "JSON problem" New topic
Author

JSON problem

RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
Hello

I am facing problem while passing json object

Following is the servlet code

JSONArray jsonArr=new JSONArray();

JSONObject json=new JSONObject();
json.put("title","Ramandeep");
json.put("start", new Date(2010,11,20));
json.put("end", new Date(2010,11,20));
json.put("allDay",true);
jsonArr.add(json);
request.addAttribute("jsonArr",jsonArr);


And Following is the jsp Code
<script type="text/javascript">

$(document).ready(function() {


var jsonObj=eval(<%=request.getAttribute("jArr").toString()%>);

});

</script>

but i am getting error

missing } after property list
[Break on this error] var jsonObj=eval([{"title":"Ramandee...end":Tue Dec 20 00:00:00 IST 3910}]);\n

If i remove date in jsonArray in servlet code then it works fine..
Can Anyone help me out Please

Thanks in Advance
Ramandeep S
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Two things:

1) It might be helpful to point out what JSON library you are using. Making us guess isn't going to get you help fast.

2) Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
Bear Bibeault wrote:Two things:

1) It might be helpful to point out what JSON library you are using. Making us guess isn't going to get you help fast.

2) Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.


Thanks for your reply first

I am using json 1.1
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
RamandeepS Singh wrote:
var jsonObj=eval(<%=request.getAttribute("jArr").toString()%>);

[...]

var jsonObj=eval([{"title":"Ramandee...end":Tue Dec 20 00:00:00 IST 3910}]);


You have to watch out for the escaping of the string.
RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
Hauke Ingmar Schmidt wrote:
RamandeepS Singh wrote:
var jsonObj=eval(<%=request.getAttribute("jArr").toString()%>);

[...]

var jsonObj=eval([{"title":"Ramandee...end":Tue Dec 20 00:00:00 IST 3910}]);


You have to watch out for the escaping of the string.


you mean to say : in the date???
but i need date object
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
No. I mean the argument you pass to eval. eval expects one string to evaluate. That is not what you supply.

Just put single quotes around the string created by your JSON library.

RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
Hauke Ingmar Schmidt wrote:No. I mean the argument you pass to eval. eval expects one string to evaluate. That is not what you supply.

Just put single quotes around the string created by your JSON library.

]

Thanks for replying

But it doesnot work
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
ItDoesntWorkIsUseless
RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
Hauke Ingmar Schmidt wrote:ItDoesntWorkIsUseless


i am sorry..

I mean to say
still facing the same problem... i applied single quotes...
and still face the same problem.. when i remove dates in my servlet code then it runs..

Please help me out

Thanks
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Ok. I still don't know which Java/JSON library you use but the date (as seen in the error message) is not encoded properly. Does your JSON library understand how to handle dates? If it is the one from JSON.org then the list of supported data types is short: JSONObject javadoc.
RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
Hauke Ingmar Schmidt wrote:Ok. I still don't know which Java/JSON library you use but the date (as seen in the error message) is not encoded properly. Does your JSON library understand how to handle dates? If it is the one from JSON.org then the list of supported data types is short: JSONObject javadoc.


Hi Hauke Ingmar Schmidt
Thanks for replying

I am new to JSON i am using it first time
Jar file i put into my lib is Json-simple-1.1.jar

Thanks & Regards
Ramandeep S
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Ok, thats JSON-simple. Please see the mapping between types. You have to care for converting your date to a string yourself.
RamandeepS Singh
Ranch Hand

Joined: Aug 25, 2009
Posts: 63
Hauke Ingmar Schmidt wrote:Ok, thats JSON-simple. Please see the mapping between types. You have to care for converting your date to a string yourself.


ok. thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSON problem