简体   繁体   English

使用datacontractjsonserializer在dataTable中序列化图像

[英]Serializing an image in a dataTable with datacontractjsonserializer

I am serializing an DataTable with datacontractjsonserializer and passing it as JSON in C#. 我正在使用datacontractjsonserializer序列化DataTable并将其作为JSON在C#中传递。 The problem im having is all the fields gets serialized as strings. 我有的问题是所有字段都被序列化为字符串。 FirstName and LastName is correct but the Picture field get serialized as 名和姓是正确的,但图片字段被序列化为

"System.Byte[]" string and not an object. “ System.Byte []”字符串,而不是对象。

Please advise how do I serialize it as an object an pass it via JSON ? 请告知如何将其序列化为对象并通过JSON传递给它?

The JSON.Net library handles the byte conversion. JSON.Net库处理字节转换。 please refer here for more details. 请参阅此处以获取更多详细信息。

covert your byte image to string like this 像这样将您的字节图像隐藏为字符串

string result=Encoding.ASCII.GetString(Your_Image);

then append the result to your fields. 然后将结果附加到您的字段。 In the other side do this split your fields to get your fields by a splitter then you can get your image like this 在另一面,将您的字段拆分成一个拆分器,然后可以像这样获取图像

byte[]your_image= Encoding.ASCII.GetBytes(Result_After_splitting) ;

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用DataContractJsonSerializer序列化Dictionary &lt;&gt;对象 - Serializing a Dictionary<> object with DataContractJsonSerializer DataContractJsonSerializer无法正确序列化 - DataContractJsonSerializer not serializing properly DataContractJsonSerializer:使用接口属性序列化一个类 - DataContractJsonSerializer: Serializing a class with an interface property 使用 DataContractJsonSerializer 序列化时出现 InvalidDataContractException - Getting InvalidDataContractException while serializing with DataContractJsonSerializer 为什么使用DataContractJsonSerializer序列化后的数组显示为空? - Why are arrays being shown as null after serializing using DataContractJsonSerializer? 使用protobuf序列化dataTable - Serializing a dataTable using protobuf 序列化数据表以供以后重用 - serializing a datatable for later reuse 使用 IPAddress 列序列化 DataTable - Serializing a DataTable with an IPAddress column 序列化数据表会引发奇怪的异常 - Serializing datatable throws strange exception 从接口序列化通用类时,如何让DataContractJsonSerializer在类型提示中使用具体类型 - How do I get DataContractJsonSerializer to use concrete type in type hint when serializing generic class from interface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM