我定义了一个类Item
public class Item : MonoBehaviour
{
public int ID { get; set; }
public string Name { get; set; }
public ItemType Type { get; set; }
public string Description { get; set; }
public int SellPrice { get; set; }
public int BuyPrice { get; set; }
public Sprite Sprite { get; set; }
public Item(int _id,string _name,ItemType _type,string _description,int _sellprice,int _buyprice,Sprite _sprite)
{
this.ID = _id;
this.Name = _name;
this.Type = _type;
this.Description = _description;
this.SellPrice = _sellprice;
this.BuyPrice = _buyprice;
this.Sprite = _sprite;
}
public Item()
{
this.ID = -1;
}
}
然后实例化出来一个item对象
Item temp=new Item(
(int)jsonData[i]["id"],
jsonData[i]["name"].ToString(),
(ItemType)System.Enum.Parse(typeof(ItemType),
jsonData[i]["type"].ToString()),
jsonData[i]["description"].ToString(),
(int)jsonData[i]["sellprice"],
(int)jsonData[i]["buyprice"],
Resources.Load<Sprite>(jsonData[i]["sprite"].ToString())
用Debug.Log(temp==null);语句判断出来的结果是true,也就是对象为空,但是Debug.Log(temp.Description);语句输出对象的属性又能够得到正确信息。
请问有没有大佬知道原因??求告知,谢谢