Google マップ API に似たいくつかの方向 API によって返された json を逆シリアル化しようとしています。私のJSONは次のとおりです(私はVB.NET 2008を使用しています):
jsontext = { "version":0.3, "status":0, "route_summary": { "total_distance":300, "total_time":14, "start_point":"43", "end_point":"42" }, " route_geometry":[[51.025421,18.647631],[51.026131,18.6471],[51.027802,18.645639]], "route_instructions": [["43 を北西に向かう",88,0,4,"88 m","NW" ,334.8],["42 を続ける",212,1,10,"0.2 km","NW",331.1,"C",356.3]] }
これまでのところ、次のコードを思いつきました。
Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
Dim lstTextAreas As Output_CloudMade() = js.Deserialize(Of Output_CloudMade())(jsontext)
複雑なクラス、つまり Output_CloudMade を定義する方法がわかりません。
私は次のようなことを試みています:
Public Class RouteSummary
Private mTotalDist As Long
Private mTotalTime As Long
Private mStartPoint As String
Private mEndPoint As String
Public Property TotalDist() As Long
Get
Return mTotalDist
End Get
Set(ByVal value As Long)
mTotalDist = value
End Set
End Property
Public Property TotalTime() As Long
Get
Return mTotalTime
End Get
Set(ByVal value As Long)
mTotalTime = value
End Set
End Property
Public Property StartPoint() As String
Get
Return mStartPoint
End Get
Set(ByVal value As String)
mStartPoint = value
End Set
End Property
Public Property EndPoint() As String
Get
Return mEndPoint
End Get
Set(ByVal value As String)
mEndPoint = value
End Set
End Property
End Class
Public Class Output_CloudMade
Private mVersion As Double
Private mStatus As Long
Private mRSummary As RouteSummary
'Private mRGeometry As RouteGeometry
'Private mRInstructions As RouteInstructions
Public Property Version() As Double
Get
Return mVersion
End Get
Set(ByVal value As Double)
mVersion = value
End Set
End Property
Public Property Status() As Long
Get
Return mStatus
End Get
Set(ByVal value As Long)
mStatus = value
End Set
End Property
Public Property Summary() As RouteSummary
Get
Return mRSummary
End Get
Set(ByVal value As RouteSummary)
mRSummary = value
End Set
End Property
'Public Property Geometry() As String
' Get
' End Get
' Set(ByVal value As String)
' End Set
'End Property
'Public Property Instructions() As String
' Get
' End Get
' Set(ByVal value As String)
' End Set
'End Property
End Class
しかし、それは機能しません。問題は、route_summary のような複雑なプロパティにあります。「何もない」に満ちている。「ステータス」や「バージョン」などの他のプロパティは適切に入力されます。
上記の JSON のクラスを定義する方法はありますか?
VB.NET で JSON を逆シリアル化するための実用的なコードを共有できますか?
ありがとう、