我已经写了一个看起来像这样的ASMX服务;读取从ASMX返回的JSON数据
namespace AtomicService
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class Validation : WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string IsEmailValid(string email)
{
Dictionary<string, string> response = new Dictionary<string, string>();
response.Add("Response", AtomicCore.Validation.CheckEmail(email).ToString());
return JsonConvert.SerializeObject(response, Formatting.Indented);
}
}
}
我正在使用Newtonsoft.Json库来提供JsonConvert.SerializeObject功能。当小提琴手电话或通过我的Jquery的访问,我得到这样的回应:
此警报的代码是:
$(document).ready(function() {
$.ajax({
type: "POST",
url: "http://127.0.0.1/AtomicService/Validation.asmx/IsEmailValid",
data: "{'email':'[email protected]'}",
contentType: "application/json",
dataType: "json",
success: function (msg) {
if (msg["d"].length > 0) {
alert("fish");
}
alert("success: " + msg.d);
},
error: function (msg) {
alert("error");
}
});
});
虽然我可以从msg.d
看到数据,我可以无法访问它。我想知道Response
是什么。我怎样才能得到它?
我不完全相信我的ASMX正在为此返回正确类型的JSON。
任何人都可以帮忙吗? :)
请参阅我的回答。 –
@C。 Ross:你解决问题的速度比原来的海报要快,并验证双JSON编码是否确实是这里的问题。我会更新我的答案以引用您的答案。 – rsp
这工作完美rsp!非常感谢。然而,我很好奇C.罗斯的回答,但你已经解决了我原来的问题。非常感谢:) – dooburt