Link to home
Start Free TrialLog in
Avatar of cofactor
cofactor

asked on

loop through list of objects

I'm doing JQuery   AJAX call to server.  Server is returning Json.  Here is the pseudo code

Server Side code
-------------------------------
................................................
// create a new Gson instance
 Gson gson = new Gson();
// make a cartList.  cartList is a list of Product objects
 // convert your list to json
String jsonCartList = gson.toJson(cartList);  
 // return your generated json
out.print( jsonCartList);  // return to UI


UI Side
------------------------
What code I will write to get the  array of  Products here ?    I am using Jquery

    $.ajax({
      url:"getvalue",
      dataType: "json"
      success:function(responseData) {
         // I'want to loop through list of Products returned by the server. what code I'll write here ?
      }
   });
Avatar of cofactor
cofactor

ASKER

comments please
But a breakpoint in the success handler and inspect what the responseData parameter contains
@gur,
Please look at my query and code again. I need a workaround.
Avatar of Rainer Jeschor
Hi,
could you please post / attach the JSON response. Without knowing the response structure we can't deliver a correct solution.
Thanks
Rainer
I made some changes in my code.
For some reason I am using dataType: "text"  (not "json" )

code and query attached  .
location
are you sure that is the correct response?

Your original question said you wanted to loop through the list of products. They don't look like products to me.
yes...thats the correct response....I made some changes to the code.  
Do you have any answer to that ?
http://jsbin.com/vowozi/1/edit?js,console

you have to set the type to "json" and jquery will parse it into an array of json objects for you
>>you have to set the type to "json"

No. I want to keep that in "text"  for some reason .....given that how do I convert the given response into array of json objects ?
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Rainer, given the question was to iterate through the objects *grin*
Hi Rob,
hopefully it ends with your solution and my assisted splitting the points as the question is indeed ambiguous - I did not "see" the issue related to create the objects array :-)
That solved my problem perfectly. Thanks guys.