Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# JsonUtility返回空列表_C#_Json_Unity3d - Fatal编程技术网

C# JsonUtility返回空列表

C# JsonUtility返回空列表,c#,json,unity3d,C#,Json,Unity3d,我试图将一些项目存储为JSON文件,并在运行时获取它们。我正在尝试创建ItemDescription对象的列表。但是这个列表又变空了。我没有收到任何错误,但当我放置断点时,我看到listOfItems在listOfItems=JsonUtility.FromJson(jsonString)之后为空 我已经尝试将所有类型更改为字符串,将itemsdescription类重命名为Items,itemslist类重命名为Items,尝试更改为此 [System.Serializable] public

我试图将一些项目存储为JSON文件,并在运行时获取它们。我正在尝试创建ItemDescription对象的列表。但是这个列表又变空了。我没有收到任何错误,但当我放置断点时,我看到
listOfItems
listOfItems=JsonUtility.FromJson(jsonString)之后为空

我已经尝试将所有类型更改为字符串,将
itemsdescription
类重命名为
Items
itemslist
类重命名为
Items
,尝试更改为此

[System.Serializable]
public class ItemList
{
    public List<ItemDescription> Items;
}
[System.Serializable]
公共类项目列表
{
公共清单项目;
}
尝试更改为此

[System.Serializable]
public class ItemList
{
    public List<ItemDescription> Items;
}
[System.Serializable]
公共类项目列表
{
公共清单项目;
}

您的类是否用“可序列化”修饰?()@Ryanya。我把它们放在
itemdograry
类的底部。它们都是可序列化的。您的类是否用“可序列化”修饰?()@Ryanya。我把它们放在
itemdograry
类的底部。它们都是
可序列化的
。哇!这就解决了!是因为我在JSON文件中定义了“Items”吗?非常感谢@D.Hariteesan不,这是因为您将其声明为
private
“具有不支持类型的字段,以及
private
字段或标有
非序列化
属性的字段将被忽略。”-直接从我在注释中链接的文档中获得。是的,命名确实重要。我总是通过运行json来获得一个起始模板,然后从那里开始@RyanWilson嘿,对不起,我没看到链接。我还公开了子类中的所有字段。您正在谈论的是
私有项目列表项
?@RyanWilson没有,实际上是因为OP的字段名
itemList
与JSON中给出的字段名
Itmes
;)不匹配哇!这就解决了!是因为我在JSON文件中定义了“Items”吗?非常感谢@D.Hariteesan不,这是因为您将其声明为
private
“具有不支持类型的字段,以及
private
字段或标有
非序列化
属性的字段将被忽略。”-直接从我在注释中链接的文档中获得。是的,命名确实重要。我总是通过运行json来获得一个起始模板,然后从那里开始@RyanWilson嘿,对不起,我没看到链接。我还公开了子类中的所有字段。您正在谈论的是
私有项目列表项
?@RyanWilson没有,实际上是因为OP的字段名
itemList
与JSON中给出的字段名
Itmes
;)不匹配
[System.Serializable]
public class ItemList
{
    public List<ItemDescription> Items;
}