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

      dataType: "json"
      success:function(responseData) {
         // I'want to loop through list of Products returned by the server. what code I'll write here ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cofactorAuthor Commented:
comments please
But a breakpoint in the success handler and inspect what the responseData parameter contains
cofactorAuthor Commented:
Please look at my query and code again. I need a workaround.
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

Rainer JeschorCommented:
could you please post / attach the JSON response. Without knowing the response structure we can't deliver a correct solution.
cofactorAuthor Commented:
I made some changes in my code.
For some reason I am using dataType: "text"  (not "json" )

code and query attached  .
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.
cofactorAuthor Commented:
yes...thats the correct response....I made some changes to the code.  
Do you have any answer to that ?
RobOwner (Aidellio)Commented:

you have to set the type to "json" and jquery will parse it into an array of json objects for you
cofactorAuthor Commented:
>>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 ?
RobOwner (Aidellio)Commented:
use JSON.parse(result)


var encryptedString = "";

  type: 'GET',
  url: 'http://jsbin.com/gilazi/1.js',
  data: { ParentlocationId: encryptedString ,locationFlag : "STATE"},
  dataType: 'text', // or 'text' or 'html'
  error: function (result) {

  success: function (result) {


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rainer JeschorCommented:
and back to your question:
this will loop through each item:
	type: 'POST', 
	url: 'getList.json', 
	data: { 
		ParentlocationId: encryptedString ,
		locationFlag : "STATE"
	dataType: 'text', 
	error: function (result) { }, 
	success: function (result) { 
		var resultAsJSON = jQuery.parseJSON(result);
		$.each(resultAsJSON, function() {
			// "this" is the current item e.g.

Open in new window

RobOwner (Aidellio)Commented:
Thanks Rainer, given the question was to iterate through the objects *grin*
Rainer JeschorCommented:
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 :-)
cofactorAuthor Commented:
That solved my problem perfectly. Thanks guys.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.