Store Hardcoded JSON string to variable

后端 未结 4 965
情书的邮戳
情书的邮戳 2021-02-05 01:48

I\'m having an issue storing this json string to a variable. It\'s gotta be something stupid I am missing here

private string someJson = @\"{
    \"ErrorMessage         


        
4条回答
  •  鱼传尺愫
    2021-02-05 02:54

    You have to escape the "'s if you use the @ symbol it doesn't allow the \ to be used as an escape after the first ". So the two options are:

    don't use the @ and use \ to escape the "

    string someJson = "{\"ErrorMessage\": \"\",\"ErrorDetails\": {\"ErrorID\": 111,\"Description\":{\"Short\": 0,\"Verbose\": 20},\"ErrorDate\": \"\"}}";
    

    or use double quotes

    string someJson =@"{""ErrorMessage"": """",""ErrorDetails"": {""ErrorID"": 111,""Description"": {""Short"": 0,""Verbose"": 20},""ErrorDate"": """"}}";
    

提交回复
热议问题