How to read Json response into Document object of Document AI in C#

214 views
Skip to first unread message

trushar tandel1

unread,
May 3, 2022, 3:04:24 AM5/3/22
to Google Cloud Developers
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);
        }          
    }

Reply all
Reply to author
Forward
0 new messages