This is a newbie question. I'm stuck with trying to deserialize a JSON object from a file to C# class object.
My JSON object looks this:
{
"text": {
"@fontName": "Helvetica",
"@fontSize": "9.0",
"@x": "629",
"@y": "67",
"@width": "126",
"@height": "9",
"#text": "844-4TX-4PMP (844-489-4767)"
}
}
Below code deserializes JSON retrieved from a file
using (StreamReader file = File.OpenText(Path.Combine(appDirectory, "json1.json")))
{
JsonSerializer serializer = new JsonSerializer();
text textObj = (text)serializer.Deserialize(file, typeof(text));
}
My C# object looks like this:
[JsonObject]
class text
{
[JsonProperty(PropertyName = "@fontName")]
public string FontName { get; set; }
[JsonProperty(PropertyName = "@fontSize")]
public string FontSize { get; set; }
[JsonProperty(PropertyName = "@x")]
public string X { get; set; }
[JsonProperty(PropertyName = "@y")]
public string Y { get; set; }
[JsonProperty(PropertyName = "@width")]
public string Width { get; set; }
[JsonProperty(PropertyName = "@height")]
public string Height { get; set; }
[JsonProperty(PropertyName = "#text")]
public string Text { get; set; }
}
I get null values returned after the object is deserialized. Can someone help point to what I'm doing wrong?
Thanks,