.Net WCF类和转换为JSON

时间:2014-03-05 11:38:10

标签: json wcf

我的WCF应用程序中有以下类 -

[DataContract(Name = "RootObject")]
public class RootObject
{
    [DataMember(Order = 1, EmitDefaultValue = true)]
    public MainDataSet dataset { get; set; }


}



[DataContract(Name = "MainDataSeta")]
public class MainDataSet
{
    [DataMember(Order = 1, EmitDefaultValue = true)]
    public List<Dimension> dimensions { get; set; }


    [DataMember(Order = 5, EmitDefaultValue = true)]
    public string source { get; set; }



    [DataMember(Order = 8, EmitDefaultValue = true)]
    public Status status { get; set; }



}



[DataContract(Name = "Dimension")]
public class Dimension
{

    [DataMember(Order = 2)]
    public Zones zones { get; set; }



}

[DataContract(Name = "Zones")]
public class Zones
{

 [DataMember(Order = 5, EmitDefaultValue = true)]
    public string zonelabel { get; set; }



}

当它被序列化为JSON时,我得到类似下面的内容

{
"dataset": {
    "dimensions": [
        {
            "zones": {
                "label": "Type of Meat"

            }
        },
        {
            "zones": {
                "label": "Year",


                }
            }
        },
        {
            "zones": {
                "label": "contents",

                }
            }
        }
    ],
  ,
   "source": "Blah",        
    "status": {
        "StatusString": "150:..,151:..,152:.."
    },

}

}

我的问题是我的尺寸可以有一个或多个“区域”所以我真的需要像这样的Json -

{
"dataset": {
    "dimensions": [
        {
            "Zone 1 - Type of Meat": {
                "label": "Type of Meat"

            }
        },
        {
            "Zone 2 - Year": {
                "label": "Year",


                }
            }
        },
        {
            "Zone 3 - Contents": {
                "label": "contents",

                }
            }
        }
    ],
  ,
   "source": "blah",        
    "status": {

"StatusString": "150:..,151:..,152:.."
    },

}
}

另外维度类在Json中被序列化为一个数组 - 再次ID就像把我的'zone'作为逗号分隔列表而不是在数组中,如果这是有意义的 -

感谢任何指针作为新的指针 感谢

0 个答案:

没有答案