Reputation: 845
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 \": \"î'ï\u0014¹\u0019ö\\±ýŽ± \u0013Eú\", }"
Upvotes: 10
Views: 37071
Reputation: 5857
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ú"", }"
Upvotes: 17
Reputation:
First of all you can use jsonlint for validate your JSON.Then you can use json2csharp for creating correct class for your JSON.
Upvotes: 4