我有一个JSON输出如下:
{
"example": {
"sub-example": [
{
"name": "123-345",
"tag" : 100
},
{
"name": "234-456",
"tag" : 100
},
{
"name": "4a7-a07a5",
"tag" : 100
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我想提取三个"名称"字段的值并将其存储在三个变量中.
我试图cat json_file | jq '.["example.sub-example.name"]'提取"名称"字段的值,但这不起作用.
谁能告诉我如何使用jq(或其他方法)实现这一目标?
我的 nginx 配置文件位于 /etc/nginx/sites-available/ 下,有两个上游说
upstream test1 {
server 1.1.1.1:50;
server 1.1.1.2:50;
}
upstream test2 {
server 2.2.2.1:60;
server 2.2.2.2:60;
}
server {
location / {
proxy_pass http://test1;
}
location / {
proxy_pass http://test2;
}
}
Run Code Online (Sandbox Code Playgroud)
向工作发送卷曲请求<PrimaryIP>:80,但我想使用<SecondaryIP1>:80fortest1和<SecondaryIP2>:80for test2。可以在nginx中定义这个吗?
我已使用此处的说明在 Ubuntu 服务器中安装了 Kubernetes 。我正在尝试使用kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --hostport=8000 --port=8080示例中列出的方法创建 pod 。但是,当我这样做时,我kubectl get pod将容器的状态设为pending. 我进一步进行kubectl describe pod了调试,并看到了以下消息:
FailedScheduling pod (hello-minikube-3383150820-1r4f7) failed to fit in any node fit failure on node (minikubevm): PodFitsHostPorts.
我进一步尝试删除这个 pod,kubectl delete pod hello-minikube-3383150820-1r4f7 但是当我进一步删除时,kubectl get pod我看到另一个带有前缀“hello-minikube-3383150820-”的 pod,我还没有创建。有谁知道如何解决这个问题?先感谢您。
我试图从我的以下curl输出中获得说"ip"的值:
{
"type":"example",
"data":{
"name":"abc",
"labels":{
"key":"value"
}
},
"subsets":[
{
"addresses":[
{
"ip":"192.168.103.178"
}
],
"ports":[
{
"port":80
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我在互联网上发现很多例子来解析curl请求的json输出,我写了下面的代码,但这似乎没有给我回复说"ip"的值
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
)
type svc struct {
Ip string `json:"ip"`
}
func main() {
url := "http://myurl.com"
testClient := http.Client{
Timeout: time.Second * 2, // Maximum of 2 secs
}
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
log.Fatal(err)
}
res, getErr := testClient.Do(req) …Run Code Online (Sandbox Code Playgroud)