处理json的常用方式

1:将json中列表对象。循环添加到数据库

List<dynamic> FileList = jss.Deserialize<List<dynamic>>(c.Request["FileList"]); 
if (FileList != null && FileList.Count > 0)
{ FileList.ForEach(x => { Model.Work.wfFiles fiel = new Model.Work.wfFiles();
fiel.FileName = x["FileName"]; fiel.FilePath = x["FilePath"];
fiel.Extend = x["Extend"];
fiel.FileType = Convert.ToInt32(x["FileType"]);
fiel.BelongTable = "pmCompanyChange";
fiel.BelongId = cid;
fiel.State = (int)StateEnum.State.Enable;
fiel.RoleId = Convert.ToInt32(CommonInfo.UserSysId(account.Id));
fiel.CompanyId = Convert.ToInt32(CommonInfo.pmCompanyId(account.Id));
fiel.CreateBy = account.AccountName; fiel.CreateById = account.Id;
fiel.CreateDate = DateTime.Now;
fiel.Id = IBLL.Factory.wfFilesCreate().Add(fiel);
fid = fiel.Id + ",";
});
}

  

2、遍历JSON数组代码如下:

var packJson = [{"name":"Liza", "password":"123"}, {"name":"Mike", "password":"456"}];
for(var i in packJson){//遍历packJson 数组时,i为索引
alert(packJson[i].name + " " + packJson[i].password);
}
posted @ 2019-10-22 16:12  没有狐狸的南墙  阅读(278)  评论(0编辑  收藏  举报