C# GetJSON检查空数据
我正在使用MVC#我有一个对象C# GetJSON检查空数据,c#,jquery,asp.net-mvc,C#,Jquery,Asp.net Mvc,我正在使用MVC#我有一个对象 public class Person { public int TypeId { get; set; } public string Code { get; set; } } 我有一个代码,可以像这样为这个对象运行JSON对象 return Json(personCodeStore.GetPersonCodes(id).Select(x=>new {text =x.Code, value =x.TypeId}), Jso
public class Person
{
public int TypeId { get; set; }
public string Code { get; set; }
}
我有一个代码,可以像这样为这个对象运行JSON对象
return Json(personCodeStore.GetPersonCodes(id).Select(x=>new {text =x.Code, value =x.TypeId}), JsonRequestBehavior.AllowGet);
如何在JSON返回数据中添加一个指示符,以便检查空数据
$.getJSON('../PersonList?id=1', function (data) {
if (data==????)
{
alert("has data");
}
else
{
alert("is Empty");
}
}
你能帮我查一下你知道的一个人的财产吗?大概是这样的:
if (data.Id) {
// We got back something with an Id property... probably a Person
} else {
// What else could we get back?!?
}
那么你希望得到什么样的数据呢?数据有哪些属性可以检查?如果(数据[0].Id){//我们得到了一个Id属性的东西…可能是一个人}其他{//我们还能得到什么?!?}啊。。。这是一个对象数组。很高兴你明白了。