C# 创建JSON模式的最佳方法?
我需要向REST api发布一个请求,该请求要求JSON以一种非常特殊的方式进行格式化: 下面是API所期望的JSON的示例文章。我如何在这个特定的模型中建模我的请求 我正在使用JSON.NETC#库 JSON模型:C# 创建JSON模式的最佳方法?,c#,json,C#,Json,我需要向REST api发布一个请求,该请求要求JSON以一种非常特殊的方式进行格式化: 下面是API所期望的JSON的示例文章。我如何在这个特定的模型中建模我的请求 我正在使用JSON.NETC#库 JSON模型: { "$type": "Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts", "Properties": { "$type": "Asi.Soa.Core.DataContract
{
"$type": "Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts",
"Properties": {
"$type": "Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts",
"$values": [
{
"$type": "Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name": "ACTIVITY_TYPE",
"Value": "ONLINEAPP"
},
{
"$type": "Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts",
"Name": "PartyId",
"Value": "22708"
}
]
}
}
最简单的选择是在VisualStudio中使用“粘贴特殊”功能。可以在编辑>粘贴特殊>将JSON粘贴为类下找到它 它将创建如下所示的类
public class Rootobject
{
public string type { get; set; }
public Properties Properties { get; set; }
}
public class Properties
{
public string type { get; set; }
public Values[] values { get; set; }
}
public class Values
{
public string type { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}