sql打印分号问题导致打印报错处理

dev
cjy 4 weeks ago
parent 794718b28b
commit 6ddc5e91e5

@ -455,7 +455,7 @@ namespace DS.WMS.PrintApi.Service
{
foreach (JsonDataSourceConnection connection in report.Dictionary.Connections)
{
connection.ConnectionString = $"JSON={JsonConvert.SerializeObject(data)};Encoding=utf-8";
connection.ConnectionString = $"JSON={JsonConvert.SerializeObject(data,new SemicolonConverter())};Encoding=utf-8";
}
//var dataSource = report.Dictionary.Connections[0] as JsonDataSourceConnection;
////dataSource.Name = "Connection";

@ -0,0 +1,39 @@
using Fizzler;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
namespace DS.WMS.PrintApi.Utils
{
public class SemicolonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
// 指定转换器适用的类型
return typeof(string).IsAssignableFrom(objectType);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
// 读取JSON时不需要进行任何操作因为我们是进行序列化
throw new NotImplementedException();
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
//new一个JObject对象,JObject可以像操作对象来操作json
var newStr = string.Empty;
var temp = (string)value;
if (temp != null && temp.Contains(";"))
{
// 写入JSON时将分号替换为其他字符
string sanitizedValue = temp.Replace(";", "");
writer.WriteValue(sanitizedValue);
}
else
{
writer.WriteValue(value);
}
}
}
}
Loading…
Cancel
Save