我的SQL Server
数据库上有2个表,我希望在我的WCF服务上合并1个JSON数组。
表1:
----------------
| type | total |
----------------
| A | 2 |
| B | 3 |
| C | 4 |
----------------
表2:
----------------
| type | total |
----------------
| A | 5 |
| B | 6 |
| C | 7 |
----------------
我想要我的JSON数组:
{"GetResult":
[
{"table1":
[
{"type":"A", "total":"2"},
{"type":"B", "total":"3"},
{"type":"C", "total":"4"}
]
},
{"table2":
[
{"type":"A", "total":"5"},
{"type":"B", "total":"6"},
{"type":"C", "total":"7"}
]
}
]
}
答案 0 :(得分:1)
答案 1 :(得分:1)
您可以创建数据合同,例如
[DataContract]
public class ResultData
{
[DataMember]
public List<DataItem> Table1 { get; set; }
[DataMember]
public List<DataItem> Table2 { get; set; }
}
[DataContract]
public class DataItem
{
[DataMember]
public string Type { get; set; }
[DataMember]
public string Total{ get; set; }
}
然后将服务合同添加为
[WebGet(UriTemplate = "/ResultData", ResponseFormat = WebMessageFormat.Json)]
ResultData GetJsonData();