Shabeer Shabeer - 4 months ago 8
C# Question

Deserialize JSON

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 :

enter image description here

can anyone please help where i am going wrong ?

Answer

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