A
Andrew
Hi,
I am using DataContractJsonSerializer to deserialize JSON string in C#
objects but I am having a problem.
Suppose I have a class:
class Item
{
public ItemId Id { get; set; }
}
class ItemId
{
public int Value { get; set; }
}
The JSON string for a Item object looks like this:
{ "Id": 100 }
The deserialization does not work since it expects that Id member is of type
int.
Even if I add a constructor like this:
class ItemId
{
public ItemId(int v)
{
Value = v;
}
public int Value { get; set; }
}
deserialization still doesn't work.
There are some workarounds like chaning the JSON and add Value but I don't
want that.
Is there a way to make deserialization to create the ItemId directly from
int ?
Thaks
I am using DataContractJsonSerializer to deserialize JSON string in C#
objects but I am having a problem.
Suppose I have a class:
class Item
{
public ItemId Id { get; set; }
}
class ItemId
{
public int Value { get; set; }
}
The JSON string for a Item object looks like this:
{ "Id": 100 }
The deserialization does not work since it expects that Id member is of type
int.
Even if I add a constructor like this:
class ItemId
{
public ItemId(int v)
{
Value = v;
}
public int Value { get; set; }
}
deserialization still doesn't work.
There are some workarounds like chaning the JSON and add Value but I don't
want that.
Is there a way to make deserialization to create the ItemId directly from
int ?
Thaks