我试图从云存储中读取json文件,并试图将其转换为Google.Cloud.DocumentAI.V1.Document。
我做了POC,但是它抛出了异常Google.Protobuf.InvalidProtocolBufferException: 'Protocol message end-group tag did not match expected tag.'
首先,我正在将.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);
}
}
我收到的错误信息是
我还有其他办法可以做到这一点吗?
发布于 2022-05-03 08:06:23
您在那里指定的代码期望数据是二进制protobuf内容。对于JSON,您希望:
string json = File.ReadAllText("C:\\upload\\temp.json");
Document document = Document.Parser.ParseJson(json);
https://stackoverflow.com/questions/72091900
复制相似问题