Unity - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(196评价)
价格: 3989.00元
老师我背包系统用json的dll解析有问题
mashiro发起了问答2017-06-21
3
回复
1254
浏览

JsonData data = JsonMapper.ToObject(File.ReadAllText(@"C:\project\package\Assets\Item.txt"));
        //List<Skill> skillTxt = new List<Skill>();
        foreach (JsonData temp in data)//这里temp表示一个对象
        {
             
            JsonData idValue = temp["id"];

            print(idValue);
        }

我这样子写的解析他抛出异常是这个求解决

InvalidOperationException: Instance of JsonData is not a dictionary
LitJson.JsonData.EnsureDictionary ()
LitJson.JsonData.System.Collections.Specialized.IOrderedDictionary.GetEnumerator ()
LitJson.JsonData.System.Collections.IDictionary.GetEnumerator ()
inventoryManager.ParseItemJson () (at Assets/Scripts/inventoryManager.cs:43)
inventoryManager.Start () (at Assets/Scripts/inventoryManager.cs:55)

所有回复
  • siki 2017-06-21

    Instance of JsonData is not a dictionary 这里说你的jsondata不是一个字典,无法遍历,那说明你的item.txt的内容有问题,内容并不是一个可以遍历的字典

    • mashiro 2017-06-23

      就是说解析json成txt的时候出问题了吗
      但是这样的代码我不用unity单独用vs去解析成功遍历

      (0) 回复
    还有-4条回复,点击查看
    你还没有登录,请先登录注册
  • siki 2017-06-23

    这里遍历的时候不要使用foreach遍历,jsondata不支持foreach遍历

    先取得里面数据的个数,然后使用for循环遍历

    还有-5条回复,点击查看
    你还没有登录,请先登录注册
发表回复
你还没有登录,请先 登录或 注册!