首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法理解/查找Unity日志引用的JSON配置文件中的错误

无法理解/查找Unity日志引用的JSON配置文件中的错误
EN

Stack Overflow用户
提问于 2021-04-04 01:14:34
回答 1查看 152关注 0票数 2

我已经为Valheim游戏中的mod自定义了这个JSON配置文件。mods使用Unity程序来加载mods,它会显示一个控制台日志,这样你就可以在加载mods时发现错误。我在Unity控制台中得到了关于该文件的持续错误,但无法理解该错误,也无法在文件的JSON格式中找到任何错误。

错误如下

代码语言:javascript
复制
[Info   :   BepInEx] Loading [Epic Loot 0.6.4]
[Error  : Unity Log] Exception: Unrecognized token at index 14451
Stack trace:
fastJSON.JsonParser.ParseValue (System.Char* p) (at <375de602811e45c183084f18a311bd14>:0)
fastJSON.JsonParser.ParseArray (System.Char* p) (at <375de602811e45c183084f18a311bd14>:0)
fastJSON.JsonParser.ParseValue (System.Char* p) (at <375de602811e45c183084f18a311bd14>:0)
fastJSON.JsonParser.ParseObject (System.Char* p) (at <375de602811e45c183084f18a311bd14>:0)
fastJSON.JsonParser.ParseValue (System.Char* p) (at <375de602811e45c183084f18a311bd14>:0)
fastJSON.JsonParser.ParseArray (System.Char* p) (at <375de602811e45c183084f18a311bd14>:0)
fastJSON.JsonParser.ParseValue (System.Char* p) (at <375de602811e45c183084f18a311bd14>:0)
fastJSON.JsonParser.ParseObject (System.Char* p) (at <375de602811e45c183084f18a311bd14>:0)
fastJSON.JsonParser.ParseValue (System.Char* p) (at <375de602811e45c183084f18a311bd14>:0)
fastJSON.JsonParser.Decode (System.Type objtype) (at <375de602811e45c183084f18a311bd14>:0)
fastJSON.deserializer.ToObject (System.String json, System.Type type) (at <375de602811e45c183084f18a311bd14>:0)
fastJSON.deserializer.ToObject[T] (System.String json) (at <375de602811e45c183084f18a311bd14>:0)
fastJSON.JSON.ToObject[T] (System.String json) (at <375de602811e45c183084f18a311bd14>:0)
EpicLoot.EpicLoot.LoadJsonFile[T] (System.String filename) (at <626516c9d3e244fa8f8ddd6519f94bb9>:0)
EpicLoot.EpicLoot.InitializeConfig () (at <626516c9d3e244fa8f8ddd6519f94bb9>:0)
EpicLoot.EpicLoot.Awake () (at <626516c9d3e244fa8f8ddd6519f94bb9>:0)
UnityEngine.GameObject:AddComponent(Type)
BepInEx.Bootstrap.Chainloader:Start()
UnityEngine.Application:.cctor()"

这是文件

https://pastebin.com/RugHLkm0

提前感谢您的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-04 01:36:01

错误消息所说的是第14451个字符是错误的(从json解析器的角度来看)。

这个字符索引对我没有多大帮助。因此,为了进一步探索这一点,我使用了removed the comments with a regex (在regex101链接中,单击左侧面板上的“替换”以查看没有注释的版本)。*

然后,我将无注释版本粘贴到一个在线JSON parser中。

输出更精确一点:

代码语言:javascript
复制
Parse error on line 368:
..., "Weight": 1 }    },    {      "Obje
----------------------^
Expecting ',', ']', got '}'

通过使用像notepad++这样的正确文本编辑器找到第368行,确实存在一些问题:

代码语言:javascript
复制
    {
      "Object": "Leech",
      "Drops": [ [0, 0], [1, 65], [2, 25], [3, 10] ],
      "Loot": [
        { "Item": "Tier2EnchantMats", "Weight": 1 }   <--- line 368 without the comments
    },

在我看来,你想要的是:

代码语言:javascript
复制
    {
      "Object": "Leech",
      "Drops": [ [0, 0], [1, 65], [2, 25], [3, 10] ],
      "Loot": [
        { "Item": "Tier2EnchantMats", "Weight": 1 }
      ]
    },

你忘了关闭数组'Loot‘!(需要右括号)

我将让您重复此过程以检查其他语法错误。

注意:*尽管一些JSON解析器可以容纳注释,但JSON规范根本没有授权它们,就像这个解析器一样。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66933866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档