1

I am trying to convert google.cloud.vision response to JSON in C#. I sent the picture to my webapi, and then I sent it to the ocr of google- here

The response returned is a google vision object, how do I convert it to JSON?

My code:

        [Route("getPrice")]
        public int GetPrice()
        {
            // Specify a Google Cloud Storage uri for the image
            // or a publicly accessible HTTP or HTTPS uri.
            var image = Image.FromUri("gs://tasmi/11.png");
            var client = ImageAnnotatorClient.Create();
            var response = client.DetectText(image);
            // I tried It ,but It's not work well
            //BatchAnnotateImagesResponse.Parser.ToString();
            BatchAnnotateImagesResponse.Parser.ParseJson(response)
            using (StreamWriter writer = new StreamWriter(fullPath))
            {
                writer.Write(response);
            }
            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                    Console.WriteLine(annotation.Description);
            }
            return 0;
        }

InUser
  • 1,138
  • 15
  • 22
sari
  • 27
  • 6

1 Answers1

1

If I understood your question correctly, you want to save the response.

Why not just save it in a list?

As in,

        var listResponse = new List<--type of annotation-->();
        foreach (var annotation in response)
        {
            if (annotation.Description != null)
                listResponse.Add(annotation.Description);
        }

Another way is to parse the response to JSON using Newtonsoft.Json.Linq For more details, here

BatshevaRich
  • 550
  • 7
  • 19