I want to read json response as name and value pairs in my jQuery code. Here is my example JSON response that I am returning from my java code:
String jsonResponse = "{"name1":"value1", "name2:value2"};
in my jQuery, if I write jsonResponse.name1 , I will get the value as "value1" . Here is my jQuery code
$.ajax({ type: 'POST', dataType:'json', url: 'http://localhost:8080/calculate', data: request, success: function(responseData) { alert(responseData.name1); }, error: function(XMLHttpRequest, textStatus, errorThrown) {
Here I want to read "name1" from jsonResponse instead of hardcoding in jQuery. Something like a loop to get an answer, getting every name and value. Any suggestions?
json jquery getjson
jgg
source share