我需要这方面的帮助:反序列化JSON对象
我的JSON(这是一个从暗黑破坏神3 API):
{
"name":"Exsanguinating Chopsword of Assault",
"icon":"mightyweapon1h_202",
"displayColor":"blue",
"tooltipParams":"item-data/COGHsoAIEgcIBBXIGEoRHYQRdRUdnWyzFB2qXu51MA04kwNAAFAKYJMD",
"requiredLevel":60,
"itemLevel":61,
"bonusAffixes":0,
"dps":{
"min":206.69999241828918,
"max":206.69999241828918
}
}
这不是完整的JSON,但我试图解析仅此因为我正在学习它。
我知道如何获取字符串名称,图标,displayColor .....但我不知道如何获得DPS。
我的模型类:
namespace Diablo_III_Profile
{
[DataContract]
public class ItemInformation : INotifyPropertyChanged
{
private string _name;
[DataMember]
public string name
{
get
{
return _name;
}
set
{
if (value != _name)
{
_name = value;
NotifyPropertyChanged("name");
}
}
}
//others strings and ints here
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
什么是DPS的“格式”把我的模型类?
要读我使用这个字符串:
MemoryStream ms = new MemoryStream();
ItemInformation data = (ItemInformation)Deserialize(ms, typeof(ItemInformation));
MessageBox.Show(data.name);
应该是一样的DPS?
编辑:
我知道了!如果是说不上来的最佳方式,但....
在我的模型类我把
public class DPS
{
public float min { get; set; }
public float max { get; set; }
}
private DPS _dps;
[DataMember]
public DPS dps
{
get
{
return _dps;
}
set
{
if (value != _dps)
{
_dps = value;
NotifyPropertyChanged("dps");
}
}
}
,你能解决问题真棒@阿德尔莫佩雷拉,但你可以用你的解决方案回答你的问题吗?它会让其他人更容易找到解决方案,这就是我们希望Sack Overflow的方式。谢谢:) – Daniel 2012-08-12 01:39:26
谢谢@Daniel!它是我第一次使用Stackoverflow来提出问题。 – 2012-08-13 16:38:52
这很酷,欢迎在这里:)希望你得到你想要的一切,并帮助其他人:) – Daniel 2012-08-13 17:01:46