Reputation: 127
I was trying to deserialize below JSON response from an API by using Newtonsoft.Json:
{
"status": "success",
"data": {
"candles": [
["2015-12-28T09:15:00+0530", 1386.4, 1388, 1381.05, 1385.1, 788],
["2015-12-28T09:16:00+0530", 1385.1, 1389.1, 1383.85, 1385.5, 609],
["2015-12-28T09:17:00+0530", 1385.5, 1387, 1385.5, 1385.7, 212],
["2015-12-28T09:18:00+0530", 1387, 1387.95, 1385.3, 1387.95, 1208],
["2015-12-28T09:19:00+0530", 1387, 1387.55, 1385.6, 1386.25, 716],
["2015-12-28T09:20:00+0530", 1386.95, 1389.95, 1386.95, 1389, 727],
["2015-12-28T09:21:00+0530", 1389, 1392.95, 1389, 1392.95, 291],
["2015-12-28T09:22:00+0530", 1392.95, 1393, 1392, 1392.95, 180],
["2015-12-28T09:23:00+0530", 1392.95, 1393, 1392, 1392.15, 1869]
...
["2016-01-01T13:22:00+0530", 1386.4, 1388, 1381.05, 1385.1, 788],
["2016-01-01T13:23:00+0530", 1385.1, 1389.1, 1383.85, 1385.5, 613],
["2016-01-01T13:24:00+0530", 1385.5, 1387, 1385.5, 1385.7, 212],
["2016-01-01T13:25:00+0530", 1387, 1387.95, 1385.3, 1387.95, 1208],
["2016-01-01T13:26:00+0530", 1387, 1387.55, 1385.6, 1386.25, 716],
["2016-01-01T13:27:00+0530", 1386.95, 1389.95, 1386.95, 1389, 727],
["2016-01-01T13:28:00+0530", 1389, 1392.95, 1389, 1392.95, 291],
["2016-01-01T13:29:00+0530", 1392.95, 1393, 1392, 1392.95, 180],
["2016-01-01T13:30:00+0530", 1392.95, 1393, 1392, 1392.15, 1869]
]
}
}
Have created below class to wrap the output but getting error while deserializing :
<Serializable()>
Public Class JSON_Model_HistoricalData
Public Property status As String
Public Property data As Data
End Class
<Serializable()>
Public Class Data
Public Property candles() As List(Of Candles_Data)
End Class
<Serializable()>
Public Class Candles_Data
Public Property candles() As String
End Class
the error message is :
can anyone please help where i am going wrong ?
Upvotes: 1
Views: 115
Reputation: 6251
This class should work:
Public Class Data
<JsonProperty("candles")>
Public Property Candles As Object()()
End Class
Public Class JSON_Model_HistoricalData
<JsonProperty("status")>
Public Property Status As String
<JsonProperty("data")>
Public Property Data As Data
End Class
Here are two tools you might consider using in future to simplify your task:
Upvotes: 0
Reputation: 11521
Try this
C#
public class Rootobject
{
public string status { get; set; }
public Data data { get; set; }
}
public class Data
{
public object[][] candles { get; set; }
}
vb
Public Class Rootobject
Public Property status As String
Public Property data As Data
End Class
Public Class Data
Public Property candles()() As Object
End Class
Upvotes: 1
Reputation: 35418
Try it with the changed class Candles_Data
holding an array of objects
<Serializable()>
Public Class Candles_Data
Public Property candles() As Object
End Class
as your arrays in the JSON hold strings as well as numbers
Upvotes: 0