2016-08-25 48 views
5

我正在尝试创建一个json文件来使用我所做的json模式以便我可以使用的intellisense和验证,以确保json我必须手工堵塞是好的。我不确定是否我的模式错了,或者我想如何让VS2015使用它。如何让JSON模式在Visual Studio 2015中工作(Intellisense和验证)

现在我已经把所有架构的东西放到一个文件中了(当时有问题试图将其拆分)。

{ 
 
    "$schema": "http://json-schema.org/schema#", 
 
    "id": "http://savatronix.com/jsonschemas/losthaven1/MainSchemaV1.json", 
 
    "title": "Lost Haven Common JSON", 
 
    "description": "A schema for json types that will be common across many different object types. V1", 
 
    "definitions": { 
 
    "gameDateTime": { 
 
     "type": "object", 
 
     "properties": { 
 
     "year": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "month": { 
 
      "type": "string", 
 
      "enum": [ "Nil", "Spring", "Summer", "Autumn", "Winter" ] 
 
     }, 
 
     "weekday": { 
 
      "type": "string", 
 
      "enum": [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ] 
 
     }, 
 
     "day": { 
 
      "type": "integer", 
 
      "minimum": 0, 
 
      "maximum": 30 
 
     }, 
 
     "hour": { 
 
      "type": "integer", 
 
      "minimum": 0, 
 
      "maximum": 23 
 
     }, 
 
     "minute": { 
 
      "type": "integer", 
 
      "minimum": 0, 
 
      "maximum": 59 
 
     }, 
 
     "second": { 
 
      "type": "integer", 
 
      "minimum": 0, 
 
      "maximum": 59 
 
     } 
 
     } 
 
    }, 
 
    "characterAttributes": { 
 
     "type": "object", 
 
     "properties": { 
 
     "strength": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "agility": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "dexterity": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "intelligence": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "endurance": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "charisma": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "luck": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     } 
 
     } 
 
    }, 
 
    "characterElements": { 
 
     "type": "object", 
 
     "properties": { 
 
     "earth": { "type": "integer" }, 
 
     "wind": { "type": "integer" }, 
 
     "fire": { "type": "integer" }, 
 
     "water": { "type": "integer" }, 
 
     "lightning": { "type": "integer" }, 
 
     "light": { "type": "integer" }, 
 
     "dark": { "type": "integer" } 
 
     } 
 
    }, 
 
    "characterStatus": { 
 
     "type": "object", 
 
     "properties": { 
 
     "poison": { "type": "integer" }, 
 
     "paralyze": { "type": "integer" }, 
 
     "sleep": { "type": "integer" }, 
 
     "fatigue": { "type": "integer" }, 
 
     "charm": { "type": "integer" }, 
 
     "confusion": { "type": "integer" } 
 
     } 
 
    }, 
 
    "characterStats": { 
 
     "type": "object", 
 
     "properties": { 
 
     "attackPower": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "block": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "health": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "defense": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "evade": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "attackSpeed": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "parry": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "stamina": { 
 
      "type": "integer", 
 
      "minimum": 0 
 
     }, 
 
     "movementSpeedModifier": { "type": "integer" }, 
 
     "elementalPower": { "$ref": "#/definitions/characterElements" }, 
 
     "statusPower": { "$ref": "#/definitions/characterStatus" } 
 
     } 
 
    }, 
 
    "attributesAndStatsContainer": { 
 
     "type": "object", 
 
     "properties": { 
 
     "attributes": { "$ref": "#/definitions/characterAttributes" }, 
 
     "stats": { "$ref": "#/definitions/characterStats" } 
 
     } 
 
    }, 
 
    "characterEquipmentState": { 
 
     "type": "object", 
 
     "properties": { 
 
     "weaponId": { "type": "string" }, 
 
     "headgearId": { "type": "string" }, 
 
     "chestId": { "type": "string" }, 
 
     "legsId": { "type": "string" }, 
 
     "bootsId": { "type": "string" }, 
 
     "glovesId": { "type": "string" }, 
 
     "firstAccessoryId": { "type": "string" }, 
 
     "secondAccessoryId": { "type": "string" } 
 
     } 
 
    }, 
 
    "baseObjectState": { 
 
     "type": "object", 
 
     "properties": { 
 
     "baseId": { "type": "string" }, 
 
     "referenceId": { "type": "string" } 
 
     } 
 
    }, 
 
    "characterState": { 
 
     "type": "object", 
 
     "allOf": [ 
 
     { "$ref": "#/definitions/baseObjectState" }, 
 
     { 
 
      "properties": { 
 
      "characterName": { "type": "string" }, 
 
      "characterSex": { 
 
       "type": "string", 
 
       "enum": [ "Unknown", "Male", "Female" ] 
 
      }, 
 
      "race": { 
 
       "type": "string", 
 
       "enum": [ "Unknown", "Human", "Yokai" ] 
 
      }, 
 
      "baseStats": { "$ref": "#/definitions/attributesAndStatsContainer" }, 
 
      "currentHealth": { 
 
       "type": "integer", 
 
       "minimum": 0 
 
      }, 
 
      "birthday": { "$ref": "#/definitions/gameDateTime" }, 
 
      "equippedItems": { "$ref": "#/definitions/characterEquipmentState" } 
 
      } 
 
     } 
 
     ] 
 
    }, 
 
    "enemyStateObject": { 
 
     "type": "object", 
 
     "allOf": [ 
 
     { "$ref": "#/definitions/characterState" }, 
 
     { 
 
      "properties": { 
 
      "isBoss": { "type": "boolean" } 
 
      } 
 
     } 
 
     ] 
 
    }, 
 
    "enemyState": { 
 
     "type": "object", 
 
     "properties": { 
 
     "enemies": { 
 
      "type": "array", 
 
      "items": { "$ref": "#/definitions/enemyStateObject" }, 
 
      "minItems": 1 
 
     } 
 
     } 
 
    }, 
 
    "NpcState": { 
 
     "type": "object", 
 
     "allOf": [ 
 
     { "$ref": "#/definitions/characterState" }, 
 
     { 
 
      "properties": { 
 
      "backgroundInfo": { "type": "string" }, 
 
      "history": { "type": "string" }, 
 
      "personalityDescription": { "type": "string" }, 
 
      "job": { 
 
       "type": "string", 
 
       "enum": [ "None" ] 
 
      }, 
 
      "isRecruitable": { "type": "boolean" }, 
 
      "isEligableSignificantOther": { "type": "boolean" }, 
 
      "significantOtherId": { "type": "string" }, 
 
      "wallet": { 
 
       "type": "integer", 
 
       "minimum": 0 
 
      }, 
 
      "inventory": { 
 
       "type": "array", 
 
       "items": { "type": "string" } 
 
      } 
 
      } 
 
     } 
 
     ] 
 
    } 
 
    } 
 
}

我试图使用enemyState定义创建包含敌人的数组(这样做是因为在MSDN博客推荐使用$架构,以便VS会自动检测对象期望的模式)。

"enemyState": { 
 
     "type": "object", 
 
     "properties": { 
 
     "enemies": { 
 
      "type": "array", 
 
      "items": { "$ref": "#/definitions/enemyStateObject" }, 
 
      "minItems": 1 
 
     } 
 
     } 
 
    },

在我Enemies.json我已经试过:

{ 
 
    "$schema": "../../../JsonSchemas/MainSchema.json#/definitions/enemyState" 
 
}

这就是 “MSDN博客文章” 推荐的方式做到这一点:Intellisense for JSON Schema in the JSON Editor

我也尝试省略,并将链接直接复制到编辑器中的模式位置栏中。

当输入$ Schema部分时,它是正确的位置,因为#/ defintions/enemyState部分正在工作智能感知。

但是,这是它的程度。尝试创建实际的json时,我没有获得智能感知或验证。我尝试关闭并重新打开该文件,以及重新启动Visual Studio。

我希望得到的效果是获得智能感知和验证,这样我就可以创建一个敌人状态对象的数组(这是我制作的游戏中的各种敌人的定义,并被读取并加载到Unity),并确保所需的属性存在(尚未在模式中创建,图中我至少添加了所需的属性后),以及确保一切都在范围内,并验证我知道没有错误。

任何帮助在这里将不胜感激。

非常感谢!

+0

我还没有看到的模式吧拿出香草VS2015更新3,是有什么事你不得不喜欢VS2013安装呢?也可以尝试看看这里的模式http://schemastore.org/json/ – kornman00

+0

不要以为我安装了什么特别的东西。这是显示在Intellisense For JSON Schema链接中的“在下拉文本框中指定模式”下的图片(打开json文件时)。 – TylerWStx

回答

0

好吧,所以我终于得到它的工作,这里是如何。

我使用解决方案资源管理器 - > json模式创建了一个测试json文件,并将其拖到JSON文件中,并且工作正常。

然后我修改它看起来完全像我的模式的相关部分(调整$ ref的,所以他们指着主要模式文件在需要的地方)。

工作。

因此,无论出于何种原因,手动创建json文件(新建 - >文本文件 - >重命名)似乎将Visual Studio关闭,并使其认为它不是直接设置为json中的模式的json文件文件(但是VS能够正确读取它,正如它从我的主模式文件,通过我的“test”json模式文件以及使用该模式的实际json文件中提取信息所证明的那样)。

去图...

相关问题