我正在使用.NET Framework 4.6.1,C#和JSON.Net开发ASP.NET Web Api应用程序。
我在返回Tuple列表时遇到问题。我得到这个json:
Option Compare Text
Public sLeave As Integer, iAnnualLeave As Integer, sLeaveType As String
Sub LeaveChecker()
Dim iAnnualLeave As Integer
bTrackingLeave = False
bReachedEndOfChart = False
bStartDateFound = False
'Set Color with If Statement
sTypeOfLeave = [D12].Value
If sTypeOfLeave = "Annual Leave" Then
sLeaveType = "AL"
ElseIf sTypeOfLeave = "Flexi Leave" Then
sLeaveType = "FL"
sLeaveTypeAmPm = "FL???"
ElseIf sTypeOfLeave = "Special Leave" Then
sLeaveType = "SpL"
ElseIf sTypeOfLeave = "Study Leave" Then
sLeaveType = "StL"
ElseIf sTypeOfLeave = "Meeting/Traning" Then
sLeaveType = "M/T"
End If
'Check to see if type of leave is populated
If sTypeOfLeave = "" Then
MsgBox ("Please Populate Type Of Leave")
End If
Application.ScreenUpdating = False
'Find last sheet name
Set ws = Sheets(Sheets.Count)
sLastSheet = ws.Name
sName = [M3].Value
If sName = "" Then
MsgBox ("Please Enter A Staff Members Name")
Exit Sub
End If
Sheets(ActiveSheet.Index + 1).Activate
SearchNewSheet:
If ActiveSheet.Name = sLastSheet Then
bReachedEndOfChart = True
GoTo LastStage
End If
Do Until ActiveSheet.Name = sLastSheet 'Main LOOP~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If bReachedEndOfChart = True Then GoTo FinalGather
'Find Person Name
[C7].Select
'Do Until ActiveCell.Row >= Finalrow
'drop out of loop if no more dates detected in row 3
Do Until sName = Cells(ActiveCell.Row, 1).Value
ActiveCell.Offset(1, 0).Select
Loop
我正在使用此代码:
[
{
"m_Item1": "88962730000000378995",
"m_Item2": 2
}
]
但我希望得到这个:
HttpResponseMessage response = null;
List<Tuple<string, byte>> exCodes = null;
[ ... ]
response = Request.CreateResponse(HttpStatusCode.OK, exCodes);
要获取该代码,我必须使用此代码:
[ {
"Item1": "88962730000000378995",
"Item2": 2
}
]
但我不确定此代码HttpResponseMessage response = null;
List<Tuple<string, byte>> exCodes = null;
[ ... ]
var j = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
j.SerializerSettings.ContractResolver = new DefaultContractResolver();
response = Request.CreateResponse(HttpStatusCode.OK, exCodes);
是否会影响服务的其余部分。
有没有其他方法可以在不使用j.SerializerSettings.ContractResolver = new DefaultContractResolver();
的情况下获取我想要的Json?
答案 0 :(得分:1)
您可以创建一个匿名对象:
var anon = exCodes.Select(x => new { x.Item1, x.Item2 });
response = Request.CreateResponse(HttpStatusCode.OK, anon);