【发布时间】:2019-04-15 00:51:04
【问题描述】:
我将 Google Cloud Vision API 与 Go SDK 结合使用。 在某些情况下,我不想使用 Golang 结构来读取 API 结果,我只想获得 API 调用的完整 JSON 响应。例如,
// detectDocumentText gets the full document text from the Vision API for an
// image at the given file path.
func detectDocumentTextURI(w io.Writer, file string) error {
ctx := context.Background()
client, err := vision.NewImageAnnotatorClient(ctx)
if err != nil {
return err
}
image := vision.NewImageFromURI(file)
annotation, err := client.DetectDocumentText(ctx, image, nil)
if err != nil {
return err
}
if annotation == nil {
fmt.Fprintln(w, "No text found.")
} else {
fmt.Fprintf(w, "API Response %s", ...JSON...)
}
return nil
}
如何从注解结构中获取 JSON?有可能吗?
【问题讨论】: