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(responseD ata) {
// I'want to loop through list of Products returned by the server. what code I'll write here ?
}
});
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(responseD
// I'want to loop through list of Products returned by the server. what code I'll write here ?
}
});
But a breakpoint in the success handler and inspect what the responseData parameter contains
ASKER
@gur,
Please look at my query and code again. I need a workaround.
Please look at my query and code again. I need a workaround.
Hi,
could you please post / attach the JSON response. Without knowing the response structure we can't deliver a correct solution.
Thanks
Rainer
could you please post / attach the JSON response. Without knowing the response structure we can't deliver a correct solution.
Thanks
Rainer
ASKER
I made some changes in my code.
For some reason I am using dataType: "text" (not "json" )
code and query attached .
location
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.
Your original question said you wanted to loop through the list of products. They don't look like products to me.
ASKER
yes...thats the correct response....I made some changes to the code.
Do you have any answer to that ?
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" and jquery will parse it into an array of json objects for you
ASKER
>>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 ?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 :-)
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 :-)
ASKER
That solved my problem perfectly. Thanks guys.
ASKER