list 序列号为字符json:字符串json序列化为list

1.list 序列号为集合List:
string saveValue = JsonConvert.SerializeObject(listValue.Select(t => new List<object> { t.AttributeValue, t.IsDefault, t.SerialNo }));
if (saveValue.Length > 3)
{
//批量更新集合
updateLst.Add(new UpdateAttibuteValues() { ID = item.AttributeID, AttibuteValues = saveValue });
}
}



02.字符串序列化为list
string sql = "select AttibuteValues from E_Amazon_ShelfTemplateAttributes(nolock) where ID=50004824";
var tt = DbContext.db.Ado.SqlQuery<TemplateAttribute>(sql);
attibuteValues = tt[0].AttibuteValues.ToString();
return JsonConvert.DeserializeObject<List<List<object>>>(attibuteValues).Select(t =>
{
var IsDefault = t[1];
var model = new TemplateAttibuteValuesModel
{
AttributeValue = t[0].ToString(),
IsDefault = Convert.ToBoolean(t[1].ToString()),
SerialNo = int.Parse(t[2].ToString())
};
return model;
}).OrderBy(t => t.AttributeValue).ToList();

posted @ 2022-08-11 18:19  大树2  阅读(260)  评论(0编辑  收藏  举报