我正在开发项目,我需要调用Web API,成功发送json数据和其他数据。现在我根据他们的文档有JSON模式,所以我想根据Schema提到的解析数据,以便我得到c#中的所有内容。
我知道我可以手动创建一个类,然后使用Newtonsoft等进行解析。但是有什么方法可以从JSON模式创建类并根据它解析输出。
我已经尝试过将JSON转换为c#的在线工具,但由于我的架构包含每个字段的属性,如需要或数据类型等等。所以即使在解析后也没有得到确切的结果..
Json架构如下
{
"description": "Rightmove Realtime Datafeed Json Schema for GetBranchPerformance response",
"type": "object",
"properties": {
"request_id": {
"type": "string",
"required": true,
"description": "The unique ID of the request which this response is associated with"
},
"message": {
"type": "string",
"required": true,
"description": "The message content for the response"
},
"success": {
"type": "boolean",
"required": true,
"description": "Indicates whether or not the request was successful"
},
"request_timestamp": {
"type": "string",
"required": true,
"description": "The time at which the request was received in the format: dd-MM-yyyy HH:mm:ss"
},
"response_timestamp": {
"type": "string",
"required": true,
"description": "The time at which the response was sent in the format: dd-MM-yyyy HH:mm:ss"
},
"replication_lag": {
"type": ["integer", "null"],
"required": false,
"description": "The current lag time for replicating between the three Rightmove data centres in minutes"
},
"export_date": {
"type": ["string", "null"],
"required": false,
"description": "The date for the export period in the format: dd-MM-yyyy"
},
"branch": {
"type": ["object","null"],
"required": false,
"description": "Information about the branch for which the metrics are being generated",
"properties": {
"branch_id": {
"type": "integer",
"id": "branch_id",
"required": true,
"description": "Unique Rightmove ID for the branch for which the performance metrics are being generated"
}
},
"additionalProperties": false
},
"performance_data": {
"type": ["object","null"],
"required": false,
"description": "Branch performance data, for the selected export date",
"properties": {
"email_leads": {
"type": "integer",
"required": true,
"description": "The total number of email leads received for a given branch, on the specified day"
},
"phone_leads": {
"type": "integer",
"required": true,
"description": "The total number of phone leads received for a given branch, on the specified day"
},
"property_data": {
"type": [
"array",
"null"
],
"id":"property_data",
"required": false,
"description": "Details about performance by property on Rightmove",
"items": {
"type": "object",
"id": "each_property_data",
"required": true,
"properties": {
"agent_ref":{
"type":"string",
"required":true,
"description":"The agent's unique reference for the property"
},
"display_address": {
"type": "string",
"required": true,
"description": "The display address of the property on Rightmove"
},
"price": {
"type": "integer",
"required": true,
"description": "The current listed price for the property on Rightmove"
},
"channel":{
"type":["integer","null"],
"id":"channel",
"required":false,
"enum":[1, 2, null],
"description":"For dual branches it specifies the channel of the property: 1 Sales 2 Lettings"
},
"rightmove_id":{
"type":"integer",
"required":true,
"description":"Rightmove's unique reference for the property"
},
"rightmove_url":{
"type":"string",
"required":true,
"description":"The Rightmove URL for the property"
},
"featured_property":{
"type":"boolean",
"required":true,
"description":"Y/N - was the property a featured property on this date?"
},
"premium_listing":{
"type":"boolean",
"required":true,
"description":"Y/N - was the property a premium listing on this date?"
},
"summary_views": {
"type": ["object","null"],
"id": "summary_views",
"required": false,
"description": "Information on a property's summary views on Rightmove on the date specified",
"properties": {
"total_summary_views": {
"type":"integer",
"required":true,
"description":"The total number of times the property has appeared in a summary view on the requested date"
},
"desktop_summary_views": {
"type":"integer",
"required":true,
"description":"The total number of times the property has appeared in a summary view on the requested date, when viewed from a desktop PC"
},
"mobile_summary_views": {
"type":"integer",
"required":true,
"description":"The total number of times the property has appeared in a summary view on the requested date, when viewed from a mobile device"
}
}
},
"detail_views": {
"type": ["object","null"],
"id": "detail_views",
"required": false,
"description": "Information on a property's detail views on Rightmove on the date specified",
"properties": {
"total_detail_views": {
"type":"integer",
"required":true,
"description":"The total number of detail views of the property on the requested date"
},
"desktop_detail_views": {
"type":"integer",
"required":true,
"description":"The total number of detail views of the property on the requested date, when viewed from a desktop PC"
},
"mobile_detail_views": {
"type":"integer",
"required":true,
"description":"The total number of detail views of the property on the requested date, when viewed from a mobile device"
}
}
}
},
"additionalProperties": false
}
}
},
"additionalProperties": false
},
"errors": {
"type": [
"array",
"null"
],
"required": false,
"description": "The errors causing the request to fail",
"minItems": 0,
"items": {
"type": [
"object",
"null"
],
"required": false,
"properties": {
"error_code": {
"type": "string",
"id": "error_code",
"required": true,
"description": "The unique Rightmove code for the error causing the request to fail"
},
"error_description":{
"type":"string",
"id":"error_description",
"required":true,
"description": "The full description of the error associated with the error code which has been generated"
},
"error_value":{
"type":["string", "null"],
"id":"error_value",
"required":false,
"description": "The value that caused this error"
}
},
"additionalProperties": false
},
"additionalProperties": false
},
"warnings": {
"type": [
"array",
"null"
],
"required": false,
"description": "The warning generated by the request",
"minItems": 0,
"items": {
"type": [
"object",
"null"
],
"required": false,
"properties": {
"warning_code": {
"type": "string",
"id": "warning_code",
"required": true,
"description": "The unique Rightmove warning code generated due to failure to pass all of the business rules"
},
"warning_description":{
"type":"string",
"id":"warning_description",
"required":true,
"description": "The full description of the warning associated with the warning code which has been generated"
},
"warning_value":{
"type":["string", "null"],
"id":"warning_value",
"required":false,
"description": "The value that caused this warning"
}
},
"additionalProperties": false
},
"additionalProperties": false
}
},
"additionalProperties": false
}