首页 > 解决方案 > 使用 C# 和 Unity 处理强大的清单项目,想知道这是否是从这个 json 文件中检索嵌套值的正确方法

问题描述

我正在尝试art从 json 文件中获取值,这包括 values sid, artId, token, name, description, width, height 。数据看起来或多或少是这样的:

{
"searchId": null,
"listings": [{
    "sid": 0,
    "id": 25,
    "status": 3,
    "art": {
        "sid": 0,
        "artId": 24,
        "token": "a5",
        "name": "Aq",
        "description": "Paint",
        "width": 18.0000,
        "height": 24.0000,
        "artist": {
            "token": null,
            "firstName": "V",
            "lastName": "G",
            "visibleInSearch": false,
            "inventoryVisibleInSearch": false
          }
         ]
    }

我正在构建一个像这样的数据库列表:new Art((int)itemData[0]["listings"]["art"][i] ["sid"]new Art((int)itemData[0]["listings"]["art"][i] ["artId"]等等。

这是获取值的正确方法art吗?

使用这种方法我得到了错误InvalidOperationException: Instance of JsonData is not a dictionary

我刚刚切换了 json 格式,因此获得更多“嵌套”数据对我来说是新的。

谢谢!

标签: c#jsonunity3d

解决方案


推荐阅读