我如何简单地打印原始 json 字符串?
How do I simply print a raw json string?
我正在尝试获取这一混乱的基础数据。这是特定于 GKE 的 PubSub 消息,我不知道底层 JSON 是什么样的。 json 中还有一个属性键,这是我最感兴趣的。有没有一种方法可以转储传入的 json,这样我就可以看到它的样子?
// Package p contains a Pub/Sub Cloud Function.
package p
import (
"context"
"log"
)
// PubSubMessage is the payload of a Pub/Sub event. Please refer to the docs for
// additional information regarding Pub/Sub events.
type PubSubMessage struct {
Data []byte `json:"data"`
}
// HelloPubSub consumes a Pub/Sub message.
func HelloPubSub(ctx context.Context, m PubSubMessage) error {
log.Println(string(m.Data))
return nil
}
json.NewEncoder(os.Stdout).Encode(&m)
应编码为 json 并写入标准输出
我正在尝试获取这一混乱的基础数据。这是特定于 GKE 的 PubSub 消息,我不知道底层 JSON 是什么样的。 json 中还有一个属性键,这是我最感兴趣的。有没有一种方法可以转储传入的 json,这样我就可以看到它的样子?
// Package p contains a Pub/Sub Cloud Function.
package p
import (
"context"
"log"
)
// PubSubMessage is the payload of a Pub/Sub event. Please refer to the docs for
// additional information regarding Pub/Sub events.
type PubSubMessage struct {
Data []byte `json:"data"`
}
// HelloPubSub consumes a Pub/Sub message.
func HelloPubSub(ctx context.Context, m PubSubMessage) error {
log.Println(string(m.Data))
return nil
}
json.NewEncoder(os.Stdout).Encode(&m)
应编码为 json 并写入标准输出