Kubectl在Windows上使用JSON格式进行修补:语法错误。

huangapple go评论72阅读模式
英文:

Kubectl patch json format on windows: syntax error

问题

Sure, here's the translated content:

> kubectl patch sts web -p '{"spec":{"replicas":3}}'

    服务器错误(BadRequest):json:无法将字符串解封为类型为 map[string]interface {} 的 Go 值

尝试将“双引号”替换为“单引号”,不起作用。

> kubectl patch sts web -p "{'spec':{'replicas':3}}"

    服务器错误(BadRequest):无效字符 '\'',查找对象键字符串的开始

Please note that I've provided the translations for the text within the angle brackets and code snippets.

英文:

> kubectl patch sts web -p '{"spec":{"replicas":3}}'

Error from server (BadRequest): json: cannot unmarshal
string into Go value of type map[string]interface {}

Tried to exchange "double quote" with "single quote", not working.

> kubectl patch sts web -p "{'spec':{'replicas':3}}"

Error from server (BadRequest): invalid character '\''
looking for beginning of object key string

答案1

得分: 0

当使用JSON时,您需要在使用空格时小心,如果您忘记添加或添加额外的空格,作为参数传递给命令的JSON字符串将不符合语法要求。

在提供的命令中,尽管您已经尝试用双引号替换单引号,但实际错误是因为未提供所需位置的空格而引起的。如果您查看这个参考文档,它们在specreplica之后都提供了空格。尝试按照相同的方式操作,您的语法错误将得到解决。我只是根据上述参考文档在您使用的命令中添加了空格。

> kubectl patch sts web -p '{ "spec" :{ "replicas" :3}}'

英文:

When using json, you need to take cautions while using spaces as well, if you forgot to add or add an extra space the json string which you pass as an argument to the command will fail the syntax requirements.

In the command provided, though you have tried replacing single quotes with double quotes the actual error is caused because of not providing spaces at required places. If you go through this reference document they have given spaces after spec and replica. Try following the same and your syntax error will get resolved. I have just added spaces in the command you are using as per the above reference.

> kubectl patch sts web -p '{"spec" :{"replicas" :3}}'

huangapple
  • 本文由 发表于 2023年5月17日 10:40:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268241.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定