我想使用C#以编程方式生成基于输入JSON数据的JSON模式。有可能吗?

时间:2017-10-24 08:54:57

标签: c# json

以下是JSON数据示例。我想以编程方式获取它的JSON模式。模式生成应该动态发生,这意味着JSON数据可以在不同的请求中不断变化

{
    "Users":[{
        "Individual": {
            "IndividualInfo": {
                "Title": "Mr",
                "Suffix": "",           
                "CountryOfBirth": "US",
                "CountryOfCitizenship": {
                    "Country": [
                        "US", "CA"
                    ]
                },
                "CountryOfResidence": "US",
                "USGreencard": "No",            
                "CountryOfMarriage": "US",
                "VIP": "Yes"
            },
            "IdentificationInfo": {
                "Identification": [{
                        "Country": "US",                    
                        "ValidToDate": "12/31/2037"
                    }, {
                        "Country": "CA",                    
                        "ValidToDate": "12/31/2019"
                    }
                ]
            },
            "EmploymentInfo": {
                "Employment": [{
                        "EmployerName": "EmpNameee",                    
                        "WorkspaceName": "SDAS"
                    }
                ]
            }
        }
    }]
}

1 个答案:

答案 0 :(得分:0)

JSON.NET Schema可以解决这个问题。这就是它的建议:

JSchemaGenerator generator = new JSchemaGenerator();

JSchema schema = generator.Generate(typeof(Users));