C# 将JSON对象保存到SQL Server数据库
将JSON对象保存到SQL Server数据库的最佳方法是什么?如何将反序列化对象保存到数据库,而不是输出到控制台?也许我可以使用实体框架?希望有人能让我走上正轨。谢谢C# 将JSON对象保存到SQL Server数据库,c#,sql-server,json,C#,Sql Server,Json,将JSON对象保存到SQL Server数据库的最佳方法是什么?如何将反序列化对象保存到数据库,而不是输出到控制台?也许我可以使用实体框架?希望有人能让我走上正轨。谢谢 public class Program { static void Main(string[] args) { string json = @"{ 'Email': 'Joebloggs@example.com', 'Active': true, 'Cr
public class Program
{
static void Main(string[] args)
{
string json = @"{
'Email': 'Joebloggs@example.com',
'Active': true,
'CreatedDate': '2015-01-20T00:00:00Z'}";
Account account = JsonConvert.DeserializeObject<Account>(json);
Console.WriteLine(account.Email);
Console.WriteLine(account.CreatedDate);
Console.ReadKey();
}
}
公共类程序
{
静态void Main(字符串[]参数)
{
字符串json=@”{
“电子邮件”:Joebloggs@example.com',
“活动”:正确,
“CreatedDate”:“2015-01-20T00:00:00Z'}”;
Account=JsonConvert.DeserializeObject(json);
字符串email=account.email.ToString();
DateTime日期=account.CreatedDate.ToDateTime();
//打开与数据库的连接。编写插入查询并提供这些值,然后运行查询。
}
}
公共课程
{
静态void Main(字符串[]参数)
{
字符串json=@”{
“电子邮件”:Joebloggs@example.com',
“活动”:正确,
“CreatedDate”:“2015-01-20T00:00:00Z'}”;
Account=JsonConvert.DeserializeObject(json);
字符串email=account.email.ToString();
DateTime日期=account.CreatedDate.ToDateTime();
//打开与数据库的连接。编写插入查询并提供这些值,然后运行查询。
}
}
是否要将反序列化的对象保存到数据库?还是序列化的字符串?创建一条insert语句,使用反序列化对象的属性值并将其插入db。反序列化对象到数据库要将反序列化的对象保存到数据库吗?还是序列化的字符串?创建一个insert语句,使用反序列化对象中的属性值,并将其插入db。反序列化对象到数据库
public class Account
{
public string Email { get; set; }
public DateTime CreatedDate { get; set; }
}
public class Program
{
static void Main(string[] args)
{
string json = @"{
'Email': 'Joebloggs@example.com',
'Active': true,
'CreatedDate': '2015-01-20T00:00:00Z'}";
Account account = JsonConvert.DeserializeObject<Account>(json);
string email=account.Email.ToString();
DateTime date=account.CreatedDate.ToDateTime();
//Open a connection with database.Write a insert query and provide these values and run the query.
}
}