欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

如何在VSCode中定制JSON的IntelliSense,vscodejson

来源: javaer 分享于  点击 29689 次 点评:237

如何在VSCode中定制JSON的IntelliSense,vscodejson


VSCode支持IntelliSense,可以方便开发者获得提醒,快速编写代码。JSON常常被用作配置文件。那么如何针对特定的开发环境来定制需要的JSON IntelliSense呢?

JSON Schema

VSCode允许用户配置JSON Schema。JSON schema用于描述和验证JSON数据,本身也是JSON。

这里是一个简单的例子。

{
    "title": "Person",
    "type": "object",
    "properties": {
        "firstName": {
            "type": "string"
        },
        "lastName": {
            "type": "string"
        },
        "age": {
            "description": "Age in years",
            "type": "integer",
            "minimum": 0
        }
    },
    "required": ["firstName", "lastName"]
}

我给Dynamsoft Barcode Reader的模板文件写了一个简单的JSON schema。

{
    "title": "JSON schema for DBR configuration files",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "description": "A representation of Dynamsoft Barcode Reader template.",
    "type": "object",
    "required": ["Version", "ImageParameters"],
    "properties": {
        "Version": {
            "description": "The template version number.",
            "type": "string",
            "enum": [
                "1.0"
            ]
        },
        "ImageParameters": {
            "description": "Parameters for barcode detection",
            "type": "object",
            "required": [
                "Name"
            ],
            "properties": {
                "Name": {
                    "description": "The name of the ImageParameters object",
                    "type": "string",
                    "maxLength": 50,
                    "minLength": 1
                },
                "Description": {
                    "description": "The description of the ImageParameters object",
                    "type": "string"
                },
                "BarcodeFormatIds": {
                    "description": "Sets which types of barcode to be read. Barcode types can be combined",
                    "type": "array",
                    "items": {
                        "type": "string",
                        "enum": [
                            "All", "OneD", "CODE_39", "CODE_128", "CODE_93", "CODABAR", "ITF", "EAN_13", "EAN_8", "UPC_A", "UPC_E", "INDUSTRIAL_25", "PDF417", "QR_CODE", "DATAMATRIX"
                        ]
                    }
                },
                "MaxBarcodesCount": {
                    "description": "Sets the maximum number of barcodes to read",
                    "type": "number",
                    "maximum": 2147483647,
                    "minimum": 1,
                    "default": 2147483647
                },
                "Timeout": {
                    "description": "Sets the maximum amount of time (in milliseconds) it should spend searching for a barcode per page",
                    "type": "number",
                    "maximum": 2147483647,
                    "minimum": 0,
                    "default": 2147483647
                },
                "ScaleDownThreshold": {
                    "description": "Sets the threshold value of the image shrinking",
                    "type": "number",
                    "maximum": 2147483647,
                    "minimum": 512,
                    "default": 2048
                },
                "DeblurLevel": {
                    "description": "The blurriness of the barcode",
                    "type": "number",
                    "maximum": 9,
                    "minimum": 0,
                    "default": 5
                }
            }
        }
    }
}

接下来在VSCode中设置一下。

"json.schemas": [
{
    "fileMatch": [
        "/tpl_*.json"
    ],
    "url": "./dbr.json"
}]

把这个dbr.json(JSON schema)文件放到工程根目录即可。


有了这个,不用担心不知道用什么key和value了。

源码

https://github.com/dynamsoft-dbr/template-json-schema

相关文章

    暂无相关文章

用户点评