asolfre / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

how to deserialize json object at client side in an ajax call which was serialized using toJson mthd #456

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1.Make a ajax call to a servlet and set the json object as below
Type listOfTestObject = new TypeToken< ArrayList <HashMap> >(){}.getType();
String sGson = new Gson().toJson(alReportsData,listOfTestObject);
response.getWriter().write(sGson); 

2.how to read the json object in ajax success call

What is the expected output? What do you see instead?
Instead i receive a parse exception SyntxaxError:JSON.parse:unexpected 
character 

What version of the product are you using? On what operating system?
 i am using google-gson-2.2.1 on Win XP

Please provide any additional information below.

$.ajax({   
type: "POST",   
url:  "/app1/servlet/Controller?destinationHandler=208&obid= " +  sObid  ,  
dataType: 'json',                            
success: function (data) {
console.log("Success... ");
   ??? How to deserialize the json object here ??? Please HELP !!
},
error: function(jqXHR, textStatus, errorThrown){
      // I get an error here
      alert(textStatus + " | " + errorThrown);
}                                                                   
});

Thanks 
Ranchs

Original issue reported on code.google.com by venkates...@gmail.com on 27 Jun 2012 at 7:28

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 30 Jun 2012 at 2:48