我一个对象里面有个对象
然后这个对象里面有个集合属性
我序列化时调试的时候时候是有答案选项这个值的
但是对应的选项这个值却为null
是什么原因啊
测试的josn:[{"QuestionBaseType":null,"QuestionType":1,"QuestionTitle":"单选题ceshi1","QuestionSelectList":["选项B","选项C","选项D"],"Answer":"A","ErrorAnalysis":"这是一个正确答案","CreateTime":"0001-01-01T00:00:00","Errors":null,"Id":0},{"QuestionBaseType":null,"QuestionType":3,"QuestionTitle":"消防验收属于二级计划ceshi1","QuestionSelectList":["错误"],"Answer":"A","ErrorAnalysis":"这是一个正确答案","CreateTime":"0001-01-01T00:00:00","Errors":null,"Id":0},{"QuestionBaseType":null,"QuestionType":3,"QuestionTitle":"项目在报集团核准时,工期可为相对时间,在项目批复后应同步修正为绝对时间ceshi1","QuestionSelectList":["错误"],"Answer":"A","ErrorAnalysis":"这是一个正确答案","CreateTime":"0001-01-01T00:00:00","Errors":null,"Id":0}]
把代码贴全, 把测试的json也都贴出来.
大概率是我猜是select和selectlist的问题, 可以考虑把list加上属性 忽略json序列化和反序列化.
什么意思,不是很明白
@灬丶: 我还以为json里面的字段是selects, 原来是selectslist, 那你把IList<>
换成 List<string>
或者string[]
@czd890: 我换成List<string>还是为null
@灬丶: 代码用文本贴出来,贴全
@czd890:
public class ExamQuestionApply : DomainBase<int>
{
/// <summary>
/// 题库id
/// </summary>
public string QuestionBank { get; set; }
/// <summary>
/// 培训资料id
/// </summary>
public int? ExamTrainMaterialId { get; set; }
/// <summary>
/// 提交人
/// </summary>
public int SubmitUser { get; set; }
/// <summary>
/// 题目
/// </summary>
public string QuestionsJson { get; set; }
/// <summary>
/// 题目
/// </summary>
public List<ExamQuestion> ExamQuestions
{
get
{
if (string.IsNullOrEmpty(QuestionsJson))
return new List<ExamQuestion>();
return JsonConvert.DeserializeObject<List<ExamQuestion>>(QuestionsJson);
}
set
{
QuestionsJson = JsonConvert.SerializeObject(value);
}
}
/// <summary>
/// 直管领导
/// </summary>
public int DeptManager { get; set; }
/// <summary>
/// 提交时间
/// </summary>
public DateTime SubmitDate { get; set; }
/// <summary>
/// 流程结束日期
/// </summary>
public DateTime? WorkFlowEndDate { get; set; }
}
[Serializable]
public class ExamQuestion:DomainBase<int>
{
/// <summary>
/// 题库
/// </summary>
public string QuestionBaseType { get; set; }
/// <summary>
/// 题型
/// </summary>
public QuestionType QuestionType { get; set; }
/// <summary>
/// 题目
/// </summary>
public string QuestionTitle { get; set; }
/// <summary>
/// 选项
/// </summary>
private string QuestionSelects { get; set; }
//private IList<string> _questionSelectList;
/// <summary>
/// 选项
/// </summary>
public List<string> QuestionSelectList
{
get
{
if (string.IsNullOrEmpty(QuestionSelects))
return new List<string>();
//_questionSelectList = QuestionSelects.Split('|');
return QuestionSelects.Split('|').ToList();
}
set
{
//_questionSelectList = value;
QuestionSelects = string.Join("|", value);
}
}
@czd890: 没啥好贴的,就是这样的
@灬丶:
private string QuestionSelects {get;}=>string.join(",",_questionSelectList);
private List<string> _questionSelectList=new List<string>();
public List<string> QuestionSelectList
{
get
{
return _questionSelectList;
}
set
{
_questionSelectList = value;
}
}
@czd890: 谢了,我自己这里弄好了,这样写的
/// <summary>
/// 选项
/// </summary>
public string QuestionSelects
{
get
{
if (QuestionSelectList == null)
return "";
return string.Join("|", QuestionSelectList);
}
set
{
QuestionSelectList = QuestionSelects.Split('|').ToList();
}
}
//private IList<string> _questionSelectList;
/// <summary>
/// 选项
/// </summary>
public List<string> QuestionSelectList{ get; set; }