简体   繁体   中英

json error Bad JSON escape sequence

I am working with json but i got an error Bad JSON escape sequence

    var model = JsonConvert.DeserializeObject<test>(def);
public class test
    {
        public string test123 { get; set; }
    }

My json def is "{\\"test123 \\": \\"î'ï\¹\ö\\\\±ýŽ± \Eú\\", }"

Please use 4 back slashes to print a single back slash in the resultant JSON string. Two slashes turns into one slash and escapes C#'s string only, to escape JSON, you will need another two. Or use can use the @ string for simplification.

"{\"test123 \": \"î'ï\u0014¹\u0019ö\\\\±ýŽ± \u0013Eú\", }"

Or

@"{""test123 "": ""î'ï\u0014¹\u0019ö\\±ýŽ± \u0013Eú"", }"

首先,您可以使用jsonlint验证您的JSON。然后您可以使用json2csharp为您的JSON创建正确的类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM