I am not able to parse tje Json object returned from the servlet in ajax,
I need to put json object values in there relative field
From my java code i am sending the below String in the form of JSON
String webVisitorDetails = "{"+"companyName : "+webVisitor.getCompanyName()+
"address : "+webVisitor.getProfessionalAddress()+
"city : "+webVisitor.getCity()+
"zipCode : "+webVisitor.getZipCode()+
"clientId : "+webVisitor.getCustomerAccountNumber()+ "}";
response.setContentType("application/json");
response.getWriter().write(webVisitorDetails);
In ajax
$.ajax({
url: "ships",
data: {
email: email.toString()
},
success: function(data) {
$.each(data, function(k, v) {
console.log(k + " Value " + v);
$("#city").text(v.city);
$("#zipcode").text(v.getZipCode);
$("#Adress").text(v.getProfessionalAddress);
});
},
error: function(data) {
console.log("error:", data);
},
type: "post"
});
you forgot the comma’s and you should quote your values
EDIT: indeed => quote your keys to (just in case)
I’m not a real java expert but yes if there is a class for that use it.