如何将JSON响应读取到C#中的文档AI的文档对象
我正在尝试从云存储中读取JSON文件,并尝试将其转换为Google.cloud.documentai.v1.document。
我已经完成了POC,但是它的投掷异常google.protobuf.invalidprotocolbufferexception:“协议消息端组标签与预期标签不匹配。”
首先,我将.json文件读取到MemoryStream中,并尝试合并到文档中。
using Google.Cloud.DocumentAI.V1;
public static void StreamToDocument()
{
byte[] fileContents = File.ReadAllBytes("C:\\upload\\temp.json");
using (Stream memoryStream = new MemoryStream(fileContents))
{
Document doc = new Document();
var byteArray = memoryStream;
doc.MergeFrom(byteArray);
}
}
错误消息我正在得到的是
我还有其他方法可以实现吗?
I am trying to read json file from cloud storage and trying to convert that into Google.Cloud.DocumentAI.V1.Document.
I have done POC, but its throwing exception Google.Protobuf.InvalidProtocolBufferException: 'Protocol message end-group tag did not match expected tag.'
First I am reading .Json file into MemoryStream and trying to Merge in to Document.
using Google.Cloud.DocumentAI.V1;
public static void StreamToDocument()
{
byte[] fileContents = File.ReadAllBytes("C:\\upload\\temp.json");
using (Stream memoryStream = new MemoryStream(fileContents))
{
Document doc = new Document();
var byteArray = memoryStream;
doc.MergeFrom(byteArray);
}
}
Error Message I am getting is
Is there any other way I can achieve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您指定的代码期望数据为 binary ProtoBuf内容。对于JSON,您想要:
The code that you've specified there expects the data to be binary protobuf content. For JSON, you want: