JSON使用小记
Newtonsoft中JArray 转成list
数据data格式(数据变量名dataJson):
[{
"clausename": "特别约定",
"proposalno": "TZAHXXXXXXXXXX",
"clausecode": "0000 "
}
{
"clausename": "期内索赔式特别约定",
"proposalno": "TZAHXXXXXXXXXX22222",
"clausecode": "00001111 "
}]
想转成list<Agreement>的格式。
我的C#类
public class Agreement{
public string ProposalNo { get; set; }
public string ClauseCode { get; set; }
public string ClauseName { get; set; }
}
转JArray再转list
JArray agreementJArry = JArray.Parse(dataJson);
List<Agreement> list= agreementJArry.ToObject<List<Agreement>>();
//客服端通过ajax提交数组过来,将JArray转为List
public IActionResult GetSpecialResponseOrderRowGuid(JArray rowguidArr)
{
List<int> rowguidList= rowguidArr.ToObject<List<int>>();
var SpecialResponseId= db.TOrders.Where(p=>rowguidList.Contains(p.rowguid) && p.IsSpecialResponse==true).Select(p=>p.rowguid).ToList();
return new JsonResult(SpecialResponseId);
}