[jQuery] $.ajax isn't parsing JSON object properly
I'm trying to digest a JSON object returned from an ASP.NET
Webservice. I'm not sure if my problem is on the ASP.NET side, or the
JavaScript side, but I could use some guidance.
This code:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "xxx",
data: "{'guid':'{85FDC9B6-C20C-4007-9AA8-AE7B62FC0309}'}",
dataType: "json",
success: function(rdata) {
//var str = eval(rdata);
$("body").append(rdata);
//alert(rdata);
}
});
Produces this:
{"guid" : "85fdc9b6-c20c-4007-9aa8-ae7b62fc0309","person_id" :
"558311","fname" : "Nkulu","mname" : "Ntanda","lname" :
"Ntambo","prefix" : "Bishop","suffix" : "","relation" :
"Jr.","ethnicity_code" : "AA","gender" : "M","conference_id" :
"68","bm_age_cat" : "MA","addr_address_id" : "32555","addr_address1" :
"United Methodist Church","addr_address2" : "P.O. Box
20219","addr_city" : "Kitwe","addr_state_code" : "","addr_zip_code" :
"","addr_country_code" : "ZAM","wk_phone_id" :
"15296","wk_country_code" : "243","wk_city_code" :
"970","wk_area_code" : "","wk_phone" : "29-004","wk_ext" :
"5555555","fax_phone_id" : "16157","fax_country_code" :
"243","fax_city_code" : "971","fax_area_code" : "","fax_phone" :
"08-9792","home_phone_id" : "32978","home_country_code" :
"222","home_city_code" : "333","home_area_code" : "","home_phone" :
"444-4444","cell_phone_id" : "","cell_country_code" :
"","cell_city_code" : "","cell_area_code" : "","cell_phone" :
"","email_id" : "4003","email_address" :
"nntambo7@hotmail.com","education" : "","recvd_loan" :
"False","grad_umcscu" : "False","grad_instit" : "","umc_scu_trustee" :
"False","trustee_instit" : "","emp_church_name" : "","pres_posit" :
"","assist_name" : "","church_memship" : "","church_size_id" :
"","loc_chur_respon" : "","ann_conf_respon" : "","gen_chur_respon" :
"","add_info" : "","spec_needs" : ""}
While this code:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "xxx",
data: "{'guid':'{85FDC9B6-C20C-4007-9AA8-AE7B62FC0309}'}",
dataType: "string", //
<-----------------------------------------------------------------------------------
success: function(rdata) {
//var str = eval(rdata);
$("body").append(rdata);
//alert(rdata);
}
});
Produces this:
"{\"guid\" : \"85fdc9b6-c20c-4007-9aa8-ae7b62fc0309\",\"person_id\" :
\"558311\",\"fname\" : \"Nkulu\",\"mname\" : \"Ntanda\",\"lname\" :
\"Ntambo\",\"prefix\" : \"Bishop\",\"suffix\" : \"\",\"relation\" :
\"Jr.\",\"ethnicity_code\" : \"AA\",\"gender\" : \"M\",\"conference_id
\" : \"68\",\"bm_age_cat\" : \"MA\",\"addr_address_id\" : \"32555\",
\"addr_address1\" : \"United Methodist Church\",\"addr_address2\" :
\"P.O. Box 20219\",\"addr_city\" : \"Kitwe\",\"addr_state_code\" :
\"\",\"addr_zip_code\" : \"\",\"addr_country_code\" : \"ZAM\",
\"wk_phone_id\" : \"15296\",\"wk_country_code\" : \"243\",
\"wk_city_code\" : \"970\",\"wk_area_code\" : \"\",\"wk_phone\" :
\"29-004\",\"wk_ext\" : \"5555555\",\"fax_phone_id\" : \"16157\",
\"fax_country_code\" : \"243\",\"fax_city_code\" : \"971\",
\"fax_area_code\" : \"\",\"fax_phone\" : \"08-9792\",\"home_phone_id
\" : \"32978\",\"home_country_code\" : \"222\",\"home_city_code\" :
\"333\",\"home_area_code\" : \"\",\"home_phone\" : \"444-4444\",
\"cell_phone_id\" : \"\",\"cell_country_code\" : \"\",\"cell_city_code
\" : \"\",\"cell_area_code\" : \"\",\"cell_phone\" : \"\",\"email_id
\" : \"4003\",\"email_address\" : \"nntambo7@hotmail.com\",\"education
\" : \"\",\"recvd_loan\" : \"False\",\"grad_umcscu\" : \"False\",
\"grad_instit\" : \"\",\"umc_scu_trustee\" : \"False\",\"trustee_instit
\" : \"\",\"emp_church_name\" : \"\",\"pres_posit\" : \"\",
\"assist_name\" : \"\",\"church_memship\" : \"\",\"church_size_id\" :
\"\",\"loc_chur_respon\" : \"\",\"ann_conf_respon\" : \"\",
\"gen_chur_respon\" : \"\",\"add_info\" : \"\",\"spec_needs\" :
\"\"};"
It looks properly formatted to me, but maybe I'm missing something.
Regardless, I cannot access any properties of the object. I would
greatly appreciate any help.
Thanks!