简体   繁体   中英

JSON schema enum to C# class equivalent

I have a JSON schema that I am trying to make a C# class out of.

The question I have lies quickly at the first property of the RootObject.

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "version": {
            "type": "string",
            "enum": [ "3.0" ]
        },
        "vectorString": {
            "type": "string"
        }
    },
    "required": [ "version" ]
}

vectorString is a string so that's easy:

public class RootObject {
    public string vectorString { get; set; }
}

However, version is a string AND has an enum modifier. My question is, how do I model static enum values in JSON schema to the C# class?

turned out I didn't need to worry about the enum metatag. just making a string property for version worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM