jQuery in Action, 2nd edition
The moose likes HTML, CSS and JavaScript and the fly likes Converting JSONArray to JSONString Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Converting JSONArray to JSONString" Watch "Converting JSONArray to JSONString" New topic
Author

Converting JSONArray to JSONString

Ashutosh Arya
Ranch Hand

Joined: Oct 07, 2008
Posts: 69
Hi..

I am sending one JsonArray to JSP and want to convert the same into JSONString..I am trying with toJSONString but it is not working fine...
My code is below


var mypostrequest = new ajaxRequest()
mypostrequest.onreadystatechange=function(){
document.getElementById('srchresult').innerHTML="Loading please wait...";
if (mypostrequest.readyState==4){
document.getElementById('srchresult').innerHTML="";
if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
var response = mypostrequest.responseText;
var jsondata=eval(response.toJSONString()); //retrieve result as an JavaScript object
var data=jsondata.items
var output='
    '
    for (var i=0; i<data.length; i++){
    alert(data[i]);
    output+='<li>'
    output+=data[i]
    output+='</li>'
    }
    output+='</ul>'
    document.getElementById("srchresult").innerHTML=output
    }


    if Anybody having any idea please reply...


    thanks
    Kanav>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56168
    
  13

Please take the time to choose the correct forum for your posts. This forum is for questions on JSP.

For more information, please read this.

This post has been moved to a more appropriate forum.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
Did you make this up: response.toJSONString() or is it part of some framework.

Eric
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
Look at my example here: http://www.coderanch.com/t/435631/HTML-JavaScript/JSON-Syntax-error#1936041

Eric
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Converting JSONArray to JSONString
 
Similar Threads
Hyper Links are not coming in div tag
OffsetLeft of LI Element
Not able to execute code for forEach loop in EL
Problem with struts-menu for second level submenu
getElementsByTagName from nested list