我正在使用 Dapper 返回一个IEnumerable<dynamic>
具有以下签名的对象:
date: 01/01/2011
VarName = "VariableX"
VariableValue = "Value 1"
date: 01/01/2011
VarName = "VariableY"
VariableValue = "Value 2"
我希望将其转换为 JSON 响应:
{ date: 01/01/2011
VariableX: Value 1
VariableY: Value 2
}
..等,并希望从哪里开始!
谢谢
编辑:
如果我将返回的对象展平,我会看到:
[
{"date":"\/Date(1331683206000)\/","VariableName":"Variable1","VariableValue":"ValueX"},
{"date":"\/Date(1331683206000)\/","VariableName":"Variable2","VariableValue":"ValueY"},
{"date":"\/Date(1331683206000)\/","VariableName":"Variable3","VariableValue":"ValueZ"}
]
我本质上正在寻找的指导是如何将其翻转出来,因此它显示为:
[
{"date":"\/Date(1331683206000)\/","Variable1","ValueX"},
{"date":"\/Date(1331683206000)\/","Variable2","ValueY"},
{"date":"\/Date(1331683206000)\/","Variable3","ValueZ"},
]
编辑#2:将所需的输出固定为:
[
{
"date": "/Date(1331683206000)/",
"Variable1": "ValueX"
},
{
"date": "/Date(1331683206000)/",
"Variable2": "ValueY"
},
{
"date": "/Date(1331683206000)/",
"Variable3": "ValueZ"
}
]
编辑#3:
{
"date": "/Date(1331683206000)/",
"Variable1": "ValueX",
"Variable2": "ValueY",
"Variable3": "ValueZ"
},
{
"date": "/Date(1431683206000)/",
"Variable1": "ValueX",
"Variable2": "ValueY",
"Variable3": "ValueZ"
},
{
"date": "/Date(151683206000)/",
"Variable1": "ValueX",
"Variable2": "ValueY",
"Variable3": "ValueZ"
}