Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#将JSON文件保存为SQL数据库中的字段需要什么数据类型?_C#_Sql_Json_Linq - Fatal编程技术网

C#将JSON文件保存为SQL数据库中的字段需要什么数据类型?

C#将JSON文件保存为SQL数据库中的字段需要什么数据类型?,c#,sql,json,linq,C#,Sql,Json,Linq,我想将s JSON文件保存为SQL数据库中的一个字段,以便于调试。我应该使用什么字段类型?我正在对JSON文件进行反序列化并保存字段,但我也希望保存原始JSON文件 public class WixOrder { [Key] public Guid OrderId { get; set; } public string Json { get; set; } [MaxLength(50)] public string OrderNumber { get;

我想将s JSON文件保存为SQL数据库中的一个字段,以便于调试。我应该使用什么字段类型?我正在对JSON文件进行反序列化并保存字段,但我也希望保存原始JSON文件

public class WixOrder
{
    [Key]
    public Guid OrderId { get; set; }

    public string Json { get; set; }

    [MaxLength(50)]
    public string OrderNumber { get; set; }
    [MaxLength(50)]
    public string RestaurantId { get; set; }
    [MaxLength(50)]
    public string Locale { get; set; }
    [MaxLength(50)]
    public string OrderDate { get; set; }
    [MaxLength(4000)]
    public string Comment { get; set; }
    public int ? Price { get; set; }
    [MaxLength(50)]
    public string Currency { get; set; }
    public List<WixOrderItem> OrderItems { get; set; }
    public WixDelivery Delivery { get; set; }
    public WixContact Contact { get; set; }
    public WixAddress Address { get; set; }
    public WixPayment Payment { get; set; }
    public long ? Created { get; set; }
    public long ? Modified { get; set; }
    public int ? ItemsCount { get; set; }
    [MaxLength(10)]
    public string TotalPrice { get; set; }
    public int SaveCount { get; set; }
    public long OrderProcessMilliseconds { get; set; }
    public long OrderSaveMilliseconds { get; set; }
    public DateTime ? DateReceived { get; set; }
    public DateTime ? DateLastPrinted { get; set; }
}
公共类WixOrder
{
[关键]
公共Guid OrderId{get;set;}
公共字符串Json{get;set;}
[MaxLength(50)]
公共字符串OrderNumber{get;set;}
[MaxLength(50)]
公共字符串RestaurantId{get;set;}
[MaxLength(50)]
公共字符串区域设置{get;set;}
[MaxLength(50)]
公共字符串OrderDate{get;set;}
[MaxLength(4000)]
公共字符串注释{get;set;}
公共整数?价格{get;set;}
[MaxLength(50)]
公共字符串货币{get;set;}
公共列表OrderItems{get;set;}
公共WixDelivery传递{get;set;}
公共WixContact联系人{get;set;}
公共WixAddress地址{get;set;}
公共WixPayment支付{get;set;}
公共long?已创建{get;set;}
公共长?修改{get;set;}
公共int?itemscont{get;set;}
[MaxLength(10)]
公共字符串TotalPrice{get;set;}
public int SaveCount{get;set;}
公共长OrderProcessMillimes{get;set;}
公共长命令保存毫秒数{get;set;}
公共日期时间?DateReceived{get;set;}
公共日期时间?DateLastPrinted{get;set;}
}

公共字符串Json{get;set;}是一个nvarchar(MAX)字段,但如果Json文件超过8000个字符,则为空。我想存储的文件有时超过400KB。

我决定将JSON文件存储在服务器上。它并不优雅,但我只需要一份JSON文件的副本进行调试

string json = null;

        using (StreamReader reader = new StreamReader(Request.InputStream))
        {
            json = await reader.ReadToEndAsync();
        }

        //store JSON for debugging
        string fileName = "wix-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff") + ".json";
        string tempFileName = Path.Combine(@"C:\Temp\Wix", fileName);
        using (StreamWriter outputFile = new StreamWriter(tempFileName, true))
        {
            await outputFile.WriteAsync(json);
        }

        Root Wix;
        try
        {
            Wix = JsonConvert.DeserializeObject<Root>(json);
        }
        catch (System.Exception ex)
        {
            string message = ex.Message;
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }

        if (!ValidWixJson(Wix)) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);

        await GetOrderAsync(Wix, json);

        return new HttpStatusCodeResult(HttpStatusCode.OK);
string json=null;
使用(StreamReader=newstreamreader(Request.InputStream))
{
json=wait reader.ReadToEndAsync();
}
//存储用于调试的JSON
字符串fileName=“wix-”+DateTime.Now.ToString(“yyyy-MM-dd-HH-MM-ss-fff”)+“.json”;
字符串tempFileName=Path.Combine(@“C:\Temp\Wix”,fileName);
使用(StreamWriter outputFile=newstreamwriter(tempFileName,true))
{
wait outputFile.WriteAsync(json);
}
根Wix;
尝试
{
Wix=JsonConvert.DeserializeObject(json);
}
catch(System.Exception-ex)
{
字符串消息=例如消息;
返回新的HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
如果(!ValidWixJson(Wix))返回新的HttpStatusCodeResult(HttpStatusCode.BadRequest);
等待GetOrderAsync(Wix,json);
返回新的HttpStatusCodeResult(HttpStatusCode.OK);

JSON文件存储在C:\Temp\Wix上。注意:我需要设置目录安全性以允许网站进程保存文件

,但如果JSON文件超过8000个字符
,则该文件为空-那么您没有正确存储它。是否要存储来自该文件的JSON数据,还是实际文件?在SQL Server中,数据类型为
nvarchar(MAX)
可以像我之前提到的那样保存2GB,这意味着用于存储字符串的代码是错误的。鉴于你提供的信息不足,我愿意假设。那么请出示。