Pass a JSON string as a command line argument

后端 未结 6 1715
一个人的身影
一个人的身影 2021-01-04 18:19

I am trying to pass a json string to a C#-Program using Commandline.

The JSON-String looks like this:

{
    \"config\": {
        \"script\": {
             


        
6条回答
  •  北海茫月
    2021-01-04 18:45

    Following on from @Selcuk Gurals post, here is a more complete answer:

    args[1].Replace("{", "{\"").Replace(":", "\":\"").Replace(",", "\",\"").Replace("}", "\"}").Replace(":\"[", ":[").Replace(":\"{", ":{").Replace("https\":\"", "https:").Replace("http\":\"", "http:").Replace("\":\"9", ":9").Replace("}\",", "},").Replace("]\",", "],").Replace("}\"}", "}}");
    

    This caters for things like embedded http/https and ports. My port number was in the 9000 region... So a regex solution would be better. But it improves on the former answer The value part of a JSON key/value pair can also be:

    1. another JSON object
    2. a list

    "key": {}, ....
    "key":[], ....
    

提交回复
热议问题