将硬编码的JSON字符串存储到变量 [英] Store Hardcoded JSON string to variable

查看:117
本文介绍了将硬编码的JSON字符串存储到变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将json字符串存储到变量时遇到问题.这一定是我在这里想念的愚蠢

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": "",
    "ErrorDetails": {
        "ErrorID": 111,
        "Description": {
            "Short": 0,
            "Verbose": 20
        },
        "ErrorDate": ""
    }
}";

推荐答案

如果使用@符号,则必须转义',不允许在第一个之后使用\进行转义.因此,这两个选项是:

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\": \"\"}}";

或使用双引号

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

这篇关于将硬编码的JSON字符串存储到变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆