我有这个类对象:
public class Gallery
{
public int Id { get; set; }
public bool IsUploaded { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public byte[] Image;
public string JobRef { get; set; }
}
我创建了它的一个实例并使用Newton JSON序列化它:
var json = JsonConvert.SerializeObject('the object');
然后我将其转换为字节数组并将其发送给另一台PC上的套接字:
byte[] byteArray = Encoding.UTF8.GetBytes(json);
using (NetworkStream serverStream = clientSocket.GetStream())
{
serverStream.Write(byteArray, 0, byteArray.Length);
//more code here but not relevant as the error happens on listening PC
}
在我的听力电脑上,我收到了json:
using (IInputStream input = args.Socket.InputStream)
{
byte[] data = new byte[BufferSize];
IBuffer buffer = data.AsBuffer();
uint dataRead = BufferSize;
while (dataRead == BufferSize)
{
await input.ReadAsync(buffer, BufferSize, InputStreamOptions.Partial);
request.Append(Encoding.UTF8.GetString(data, 0, data.Length));
dataRead = buffer.Length;
}
}
var job = JsonConvert.DeserializeObject<Gallery>(request.ToString());
在最后一行我收到错误:
Additional text encountered after finished reading JSON content: r. Path '', line 34, position 2.
然而,如果我删除字节数组图像,则没有错误。那么,是否有某种方法可以将图像数组包含在json对象中?
由于