私は
class Product
{
public IComponent[] components;
}
次のようなJSON記述から製品オブジェクトを逆シリアル化する最も簡単な方法は何ですか
{
"components": [
{"type":"ComponentA", "key":value}
{"type":"ComponentB", "key":value}
]
}
?
ありがとう。
私は
class Product
{
public IComponent[] components;
}
次のようなJSON記述から製品オブジェクトを逆シリアル化する最も簡単な方法は何ですか
{
"components": [
{"type":"ComponentA", "key":value}
{"type":"ComponentB", "key":value}
]
}
?
ありがとう。
Json.Netを使用する
string json = JsonConvert.SerializeObject(product);
または使用JavaScriptSerializer
string json = new JavaScriptSerializer().Serialize(product);
そして逆の操作
var product = JsonConvert.DeserializeObject<Product>(json)
また
var product = new JavaScriptSerializer().Deserialize<Product>(json)