I would like to deserialize a string o JSON and output data on a string:
public class Test
{
public int id { get; set; }
public string name { get; set; }
public long revisionDate { get; set; }
}
private void btnRetrieve_Click(object sender, EventArgs e)
{
string json = @"{""Name"":{""id"":10,""name"":""Name"",""revisionDate"":1390293827000}}";
var output = JsonConvert.DeserializeObject<Test>(json);
lblOutput.Text = output.name;
}
This is intended to output the name
property of the string json
. However, it returns nothing.
The JSON you posted can be deserialized into an object which has a Name
propery of type Test
, not into a Test
instance.
This
string json = @"{""id"":10,""name"":""Name"",""revisionDate"":1390293827000}";
would be a representation of a Test
instance.
Your JSON may be deserialized into something like this:
public class Test
{
public int id { get; set; }
public string name { get; set; }
public long revisionDate { get; set; }
}
public class Foo
{
public Test Name { get; set; }
}
// ...
var output = JsonConvert.DeserializeObject<Foo>(json);
lblOutput.Text = output.Name.name;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With