Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 创建JSON模式的最佳方法?_C#_Json - Fatal编程技术网

C# 创建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

我需要向REST api发布一个请求,该请求要求JSON以一种非常特殊的方式进行格式化:

下面是API所期望的JSON的示例文章。我如何在这个特定的模型中建模我的请求

我正在使用JSON.NETC#库

JSON模型:

{
    "$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; }
}