【发布时间】:2020-03-15 06:56:35
【问题描述】:
在网络服务中,我尝试将 jzonString 转换为列表。
{
"name": "Test",
"Fname": "Testing",
"S1": "Content1",
"S2": "Content2",
"S3": "Content3"
}
[WebMethod]
public int Create(string Detils, string Companyid)
{
try
{
dynamic ScheduleShift = new JavaScriptSerializer().DeserializeObject(Detils);
\\ i need to set data to list or to an object
InvDetails objDetails = new InvDetails();
List<InvDetails> lstDetails = new List<InvDetails>();
return objDetails.CreateInvDetails(objDetils);
}
catch (Exception ex)
{
// Abort Transaction
throw ex;
}
}
创建另一个库文件来声明对象并插入到数据库中
public class Inventory
{
CommonExecDAL CommonExecDAL = new CommonExecDAL();
public string name { get; set; }
public string Fname { get; set; }
public string S1 { get; set; }
public string S2 { get; set; }
public string S3 { get; set; }
public int intCompanyId { get; set; }
public int CreateInvComputer(InvDetails objInvDetails)
{
SqlParameter[] arParms = new SqlParameter[6];
.........
}
}
【问题讨论】:
-
NewtonSoft.Json 是您应该使用的库。互联网上有大量关于如何将其用于 Jain 序列化和反序列化的示例。
-
您可以将 JSON array 反序列化为列表。但是您的 JSON 是单个对象