这是角度http呼叫:
$http({
url: "SingleSNP30second.aspx/GetSummary",
method: "POST",
data: { summaryId: $scope.summaryId },
headers: { 'Content-Type': 'application/json; charset=utf-8' }
});
这是asp web方法:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static List<SummaryInfoJson> GetSummary(int summaryId)
{
DeveloprodDataClassDataContext masterDb = new DeveloprodDataClassDataContext();
List<SummaryInfoJson> Summaries = (from t in masterDb.tbl_thirty_second_summaries_single_snps
join g in masterDb.tbl_custom_SNP_Genotypes on t.GenotypeId equals g.GenotypeId_this
join v in masterDb.tbl_custom_SNP_Variants on t.VariantId equals v.SnpsVariantId_this
join s in masterDb.tbl_thirty_second_summaries_stop_light_colors on t.StopLightColorId equals s.StopLightColorId_this
join l in masterDb.tbl_thirty_second_summaries_levels_of_evidences on t.LevelOfEvidenceId equals l.LevelOfEvidenceId_this
join d in masterDb.tbl_custom_SNP_Drugs_Apelon_NUIs on t.DrugId equals d.SnpsDrugId_this
join m in masterDb.tbl_thiry_second_summaries_summary_states on t.SummaryStateId equals m.SummaryStateId_this
join u in masterDb.tbl_users on t.EntrantUserId equals u.userId_this
where t.OriginalSummaryId == summaryId
select new SummaryInfoJson
(
t.ThirtySecondSummaryId_this,
d.Drug,
v.Variant,
g.Genotype,
t.ThirtySecondSummary,
s.StopLightColor,
l.LevelOfEvidence,
u.userName,
m.SummaryState
)
).ToList();
return Summaries;
}
以下是SummaryInfoJson类的定义:
[Serializable]
public class SummaryInfoJson
{
int ThirtySecondSummaryId;
string Drug {get; set;}
string Variant {get; set;}
string Genotype {get; set;}
string ThirtySecondSummary { get; set; }
string StopLightColor { get; set; }
string LevelOfEvidence { get; set; }
string UserName { get; set; }
string SummaryState { get; set; }
public SummaryInfoJson(int thirtySecondSummaryId, string drug, string variant, string genotype, string thirtySecondSummary, string stopLightColor,
string levelOfEvidence, string userName, string summaryState)
{
this.ThirtySecondSummaryId = thirtySecondSummaryId;
this.Drug = drug;
this.Variant = variant;
this.Genotype = genotype;
this.ThirtySecondSummary = thirtySecondSummary;
this.StopLightColor = stopLightColor;
this.LevelOfEvidence = levelOfEvidence;
this.UserName = userName;
this.SummaryState = summaryState;
}
}
在调试时,我可以看到数据库调用正常工作,Summaries初始化为SummaryInfoJson对象的List。不知怎的,http响应不包含对象,它只是一个空数组......
我没有包含SummaryInfoJson的定义以及数据库调用以保持代码简短。如果你愿意,我绝对可以提供。
编辑:好的,我在网络方法中添加了以下内容:
string returnVar = new JavaScriptSerializer().Serialize(Summaries);
return returnVar;
returnVar为空。错误发生在序列化中。为什么我的列表没有被序列化?我将serializable属性添加到该类定义..
答案 0 :(得分:0)
尝试制作SummaryInfoJson public
的属性,例如
public class SummaryInfoJson
{
public string Drug {get; set;}
public string Variant {get; set;}
....
}