英文:
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字符串将不符合语法要求。
在提供的命令中,尽管您已经尝试用双引号替换单引号,但实际错误是因为未提供所需位置的空格而引起的。如果您查看这个参考文档,它们在spec和replica之后都提供了空格。尝试按照相同的方式操作,您的语法错误将得到解决。我只是根据上述参考文档在您使用的命令中添加了空格。
> 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}}'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论