传递JSON字符串作为命令行参数 [英] Pass a JSON string as a command line argument
本文介绍了传递JSON字符串作为命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用命令行将json字符串传递给C#-Program.
I am trying to pass a json string to a C#-Program using Commandline.
JSON字符串如下所示:
The JSON-String looks like this:
{
"config": {
"script": {
"script_name": "test",
"dir": "D:\\test",
"destination": "M:\\neu\\test",
"params": "/b /s /r:3 /w:5"
}
}
}
在命令行中,它看起来像这样:
In Commandline it looks like this:
{"config":{"script":{"script_name":"test","dir":"D:\\test","destination":"M:\\neu\\test","params":"/b /s /r:3 /w:5"}}}
但是,如果我只是传递字符串,那么它将被分成几部分.但是我希望程序将其视为单个字符串.
But if I just pass the string then it gets chunked into several pieces. But I want my program to see it as just a single string.
我必须修改我的JSON-String吗?
Do I have to adapt my JSON-String?
推荐答案
使用""
将其声明为字符串,并使用\
转义另一个"
,它应该可以工作.
Declare it as a string with ""
and escape the other "
with \
and it should work.
命令行:
"{\"config\":{\"script\":{\"script_name\":\"test\",\"dir\":\"D:\\test\",\"destination\":\"M:\\neu\\test\",\"params\":\"/b /s /r:3 /w:5\"}}}"
这篇关于传递JSON字符串作为命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文