AJAXを介してデータを自分のDBに挿入するASP.NET Webサービスにデータをプッシュしようとしています。しかし、私はデシリアライズされたリストを通して問題を繰り返しています。ここでJsonConvert.DeserializeObjectは欠損値を返します
は私のクラスである:
Public Class TimesheetDetails
Inherits System.Web.Services.WebService
Public Property TimesheetID() As String
Get
Return m_TimesheetID
End Get
Set
m_TimesheetID = Value
End Set
End Property
Private m_TimesheetID As String
Public Property LineNumber() As String
Get
Return m_LineNumber
End Get
Set
m_LineNumber = Value
End Set
End Property
Private m_LineNumber As String
Public Property ProjectCode() As String
Get
Return m_ProjectCode
End Get
Set
m_ProjectCode = Value
End Set
End Property
Private m_ProjectCode As String
Public Property Comments() As String
Get
Return m_Comments
End Get
Set
m_Comments = Value
End Set
End Property
Private m_Comments As String
Public Property SAT() As Decimal
Get
Return m_SAT
End Get
Set
m_SAT = Value
End Set
End Property
Private m_SAT As Decimal
Public Property SUN() As Decimal
Get
Return m_SUN
End Get
Set
m_SUN = Value
End Set
End Property
Private m_SUN As Decimal
Public Property MON() As Decimal
Get
Return m_MON
End Get
Set
m_MON = Value
End Set
End Property
Private m_MON As Decimal
Public Property TUE() As Decimal
Get
Return m_TUE
End Get
Set
m_TUE = Value
End Set
End Property
Private m_TUE As Decimal
Public Property WED() As Decimal
Get
Return m_WED
End Get
Set
m_WED = Value
End Set
End Property
Private m_WED As Decimal
Public Property THU() As Decimal
Get
Return m_THU
End Get
Set
m_THU = Value
End Set
End Property
Private m_THU As Decimal
Public Property FRI() As Decimal
Get
Return m_FRI
End Get
Set
m_FRI = Value
End Set
End Property
Private m_FRI As Decimal
Public Property TOTAL() As Decimal
Get
Return m_TOTAL
End Get
Set
m_TOTAL = Value
End Set
End Property
Private m_TOTAL As Decimal
End Class
及び方法
<WebMethod()>
Public Function SaveData(empdata) As String
'WebMethod to Save the data
Dim serializeData = JsonConvert.DeserializeObject(Of List(Of TimesheetDetails))(empdata)
Dim ids As String = ""
For Each obj As Object In serializeData
If obj.LineNumber = "0" Then
Else
Dim timesheetid As String = obj.TimesheetID
Dim linenumber As String = obj.LineNumber
Dim projectcode As String = obj.ProjectCode
Dim comments As String = obj.Comments
Dim monday As String = obj.MON
Dim tuesday As String = obj.TUE
Dim wednesday As String = obj.WED
Dim thursday As String = obj.THU
Dim friday As String = obj.FRI
Dim saturday As String = obj.SAT
Dim sunday As String = obj.SUN
Dim total As String = obj.TOTAL
Dim noteid As String = "No id found"
Debug.WriteLine(linenumber + " | " + projectcode + ", " + monday + tuesday + wednesday + thursday + friday + saturday + sunday)
End If
Next
Return Nothing
End Function
データはそのままAJAXポストから到着したが、データをデシリアライズされたとき、私の値のいくつかは、同じまま他はnullまたは0になります。
これまでの値は次のとおりです。
[
{
"timesheetid":"86",
"linenumber":0
},
{
"timesheetid":"86",
"linenumber":1,
"projectcode":"12988",
"comments":" test comment",
"monday":"7.5",
"tuesday":"7.5",
"wednesday":"7.5",
"thursday":"7.5",
"friday":"7",
"saturday":"7.5",
"sunday":"7.5",
"total":"52"
}
]
、ここでデータをデシリアライズされた後、値は次のとおりです。
[
{
"timesheetid":"86",
"linenumber":0
},
{
"timesheetid":"86",
"linenumber":1,
"projectcode":"12988",
"comments":" test comment",
"monday":"0",
"tuesday":"0",
"wednesday":"0",
"thursday":"0",
"friday":"0",
"saturday":"0",
"sunday":"0",
"total":"52"
}
]
問題は* TimesheetDetails *クラスのいくつかのプロパティが投稿されたオブジェクトのプロパティと異なると思う。たとえば、投稿オブジェクトのプロパティはname * monday *ですが、* TimesheetDetails *クラスのプロパティは* MON *です。 –
こんにちは@Trung Duong、答えとしてあなたの上記のコメントを追加してください、私はマークが解決されていることができますか?どうもありがとうございました!! –
ありがとう@クリス。私は答えを加えました。 –