【发布时间】:2012-08-12 00:31:13
【问题描述】:
我需要帮助:
我的 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,但我正在尝试仅解析这一部分,因为我正在学习它。
我知道如何获取字符串名称、图标、显示颜色.....但我不知道如何获取 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");
}
}
}
【问题讨论】:
-
太棒了@adelmo-pereira,你解决了你的问题,但你能用你的解决方案回答你的问题吗?它会让其他人更容易找到解决方案,这就是我们想要 Sack Overflow 上的东西的方式。谢谢:)
-
谢谢@Daniel!这是我第一次使用 Stackoverflow 提问。
-
这很酷,欢迎来到这里 :) 希望你得到你想要的一切,也帮助其他一些人 :)
标签: json api serialization windows-phone-7.1