I am trying to deserialize a JSON message using Newtonsoft.Json
but one of his attributes has a space and returns null as result.
My code to deserialize the message:
JavaScriptSerializer jss;
jss = new JavaScriptSerializer();
using (reader = new StreamReader(stream))
{
string message = reader.ReadToEnd();
JsonError jsonError = new JsonError();
jsonError = jss.Deserialize<JsonError>(message);
btxErrorMemo.Visible = true;
btxErrorMemo.Text = errorMessage;
btxStatusLbl.Text = "ERROR";
}
I show that you have to specify Json attributes to class when the message contains spaces
JsonError class
public class JsonError
{
[JsonProperty("error")] //this one works
public string error { get; set; }
public string description { get; set; }
[JsonProperty("error message")] //this one doesnt work
public IList<string> errorMessage { get; set; }
}
The JSON message is like this
{
"error":"xml data validation ",
"error message": ["\u03a4\u03bf \u03c0\u03b5\u03b4\u03af\u03bf MesIdeMES19 \u03c0\u03c1\u03ad\u03c0\u03b5\u03b9 \u03bd\u03b1 \u03b5\u03af\u03bd\u03b1\u03b9 \u03bc\u03bf\u03bd\u03b1\u03b4\u03af\u03ba\u03bf\u03c2 \u03b1\u03c1\u03b9\u03b8\u03bc\u03cc\u03c2.(\u03a0\u03c1\u03bf\u03c4\u03b5\u03af\u03bd\u03b5\u03c4\u03b1\u03b9 \u03bd\u03b1 \u03b5\u03af\u03bd\u03b1\u03af \u03bf \u03b1\u03c1\u03b9\u03b8\u03bc\u03cc\u03c2 VAT \u03c4\u03b7\u03c2 \u03b5\u03c4\u03b1\u03b9\u03c1\u03b5\u03af\u03b1\u03c2 \u03b7 \u03c3\u03b7\u03bc\u03b5\u03c1\u03b9\u03bd\u03ae \u0397\u03bc\u03b5\u03c1\u03bf\u03bc\u03b7\u03bd\u03af\u03b1. \u03ba\u03b1\u03b9 6 \u03c4\u03c5\u03c7\u03b1\u03af\u03b1 \u03b1\u03bb\u03c6\u03b1\u03c1\u03b1\u03c1\u03b9\u03b8\u03bc\u03b9\u03c4\u03ba\u03ac)","\u03a3\u03c4\u03bf \u03b5\u03bc\u03c0\u03cc\u03c1\u03b5\u03c5\u03bc\u03b1:1 \u03a4\u03bf \u03c0\u03ad\u03b4\u03b9\u03bf (GooDesGDS23) \u03a0\u03b5\u03c1\u03b9\u03b3\u03c1\u03b1\u03c6\u03ae \u03b5\u03af\u03b4\u03bf\u03c5\u03c2 \u03c0\u03c1\u03ad\u03c0\u03b5\u03b9 \u03bd\u03b1 \u03b5\u03af\u03bd\u03b1\u03b9 \u03b1\u03bb\u03c6\u03b1\u03c1\u03b9\u03b8\u03bc\u03b7\u03c4\u03b9\u03ba\u03cc"]
}
I changed the "error message" from
public string errorMessage { get; set; }
to
public IList<string> errorMessage { get; set; }
because I saw that the error message belongs to array and not just string but I keep getting null as result.