Oyedepo Olufemi

Oyedepo Olufemi

  • 1.4k
  • 334
  • 29.6k

Need help deserializing a json response

Aug 4 2020 1:59 AM
Hello everyone,
 
Ive been stucked on this for quite some time, kindly help look into this, I can't seem to pick out what the error is here....
 
{ "code": 500, "message": "Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ChakaIntegration.API.Models.Response.Instruments.InstrumentsAnalytics' because the type requires a JSON object
(e.g. {\"name\":\"value\"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {\"name\":\"value\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array.
JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath 'data', line 1, position 45.", "data": null, "success": false }
 
Here is my json:
 
{
"code": "200",
"message": "Successful",
"data": {
"code": "200",
"message": "Successful",
"data": [
{
"consensusEndDate": null,
"consensusStartDate": 1596153600000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 23,
"ratingHold": 8,
"ratingNone": 0,
"ratingOverweight": 3,
"ratingScaleMark": 1.434211,
"ratingSell": 2,
"ratingUnderweight": 2
},
{
"consensusEndDate": 1596067200000,
"consensusStartDate": 1595376000000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 23,
"ratingHold": 8,
"ratingNone": 0,
"ratingOverweight": 3,
"ratingScaleMark": 1.447368,
"ratingSell": 3,
"ratingUnderweight": 1
},
{
"consensusEndDate": 1595289600000,
"consensusStartDate": 1594944000000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 23,
"ratingHold": 9,
"ratingNone": 0,
"ratingOverweight": 3,
"ratingScaleMark": 1.421053,
"ratingSell": 2,
"ratingUnderweight": 1
},
{
"consensusEndDate": 1594857600000,
"consensusStartDate": 1594598400000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 23,
"ratingHold": 10,
"ratingNone": 0,
"ratingOverweight": 3,
"ratingScaleMark": 1.435897,
"ratingSell": 2,
"ratingUnderweight": 1
},
{
"consensusEndDate": 1594512000000,
"consensusStartDate": 1594166400000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 23,
"ratingHold": 11,
"ratingNone": 0,
"ratingOverweight": 3,
"ratingScaleMark": 1.45,
"ratingSell": 2,
"ratingUnderweight": 1
},
{
"consensusEndDate": 1594080000000,
"consensusStartDate": 1591920000000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 23,
"ratingHold": 11,
"ratingNone": 0,
"ratingOverweight": 3,
"ratingScaleMark": 1.4375,
"ratingSell": 1,
"ratingUnderweight": 2
},
{
"consensusEndDate": 1591833600000,
"consensusStartDate": 1591660800000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 24,
"ratingHold": 11,
"ratingNone": 0,
"ratingOverweight": 3,
"ratingScaleMark": 1.426829,
"ratingSell": 1,
"ratingUnderweight": 2
},
{
"consensusEndDate": 1591574400000,
"consensusStartDate": 1589500800000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 24,
"ratingHold": 10,
"ratingNone": 0,
"ratingOverweight": 3,
"ratingScaleMark": 1.45122,
"ratingSell": 2,
"ratingUnderweight": 2
},
{
"consensusEndDate": 1589414400000,
"consensusStartDate": 1589328000000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 25,
"ratingHold": 10,
"ratingNone": 0,
"ratingOverweight": 3,
"ratingScaleMark": 1.440476,
"ratingSell": 2,
"ratingUnderweight": 2
},
{
"consensusEndDate": 1589241600000,
"consensusStartDate": 1588896000000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 24,
"ratingHold": 10,
"ratingNone": 0,
"ratingOverweight": 3,
"ratingScaleMark": 1.45122,
"ratingSell": 2,
"ratingUnderweight": 2
},
{
"consensusEndDate": 1588809600000,
"consensusStartDate": 1588291200000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 25,
"ratingHold": 10,
"ratingNone": 0,
"ratingOverweight": 3,
"ratingScaleMark": 1.440476,
"ratingSell": 2,
"ratingUnderweight": 2
},
{
"consensusEndDate": 1588204800000,
"consensusStartDate": 1587427200000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 25,
"ratingHold": 9,
"ratingNone": 0,
"ratingOverweight": 3,
"ratingScaleMark": 1.426829,
"ratingSell": 2,
"ratingUnderweight": 2
},
{
"consensusEndDate": 1587340800000,
"consensusStartDate": 1586995200000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 26,
"ratingHold": 9,
"ratingNone": 0,
"ratingOverweight": 2,
"ratingScaleMark": 1.414634,
"ratingSell": 2,
"ratingUnderweight": 2
},
{
"consensusEndDate": 1586908800000,
"consensusStartDate": 1586822400000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 26,
"ratingHold": 10,
"ratingNone": 0,
"ratingOverweight": 2,
"ratingScaleMark": 1.390244,
"ratingSell": 1,
"ratingUnderweight": 2
},
{
"consensusEndDate": 1586736000000,
"consensusStartDate": 1586304000000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 26,
"ratingHold": 11,
"ratingNone": 0,
"ratingOverweight": 2,
"ratingScaleMark": 1.378049,
"ratingSell": 1,
"ratingUnderweight": 1
},
{
"consensusEndDate": 1586217600000,
"consensusStartDate": 1586131200000,
"corporateActionsAppliedDate": 1402272000000,
"ratingBuy": 26,
"ratingHold": 10,
"ratingNone": 0,
"ratingOverweight": 2,
"ratingScaleMark": 1.3625,
"ratingSell": 1,
"ratingUnderweight": 1
}
],
"success": true
},
"success": true
}
 
And here are my POCO Classes:
  1. public class InstrumentsAnalyticsResponse  
  2.     {  
  3.         [JsonProperty("code")]  
  4.         public long Code { getset; }  
  5.   
  6.         [JsonProperty("message")]  
  7.         public string Message { getset; }  
  8.   
  9.         [JsonProperty("data")]  
  10.         public InstrumentAnalytics Data { getset; }  
  11.   
  12.         [JsonProperty("success")]  
  13.         public bool Success { getset; }  
  14.     }  
  15.   
  16.     public class InstrumentAnalytics  
  17.     {  
  18.         [JsonProperty("code")]  
  19.         public long Code { getset; }  
  20.   
  21.         [JsonProperty("message")]  
  22.         public string Message { getset; }  
  23.   
  24.         [JsonProperty("data")]  
  25.         public List<AnalyticsData> Data { getset; }  
  26.   
  27.         [JsonProperty("success")]  
  28.         public bool Success { getset; }  
  29.     }  
  30.   
  31.     public class AnalyticsData  
  32.     {  
  33.         [JsonProperty("consensusEndDate")]  
  34.         public long? ConsensusEndDate { getset; }  
  35.   
  36.         [JsonProperty("consensusStartDate")]  
  37.         public long ConsensusStartDate { getset; }  
  38.   
  39.         [JsonProperty("corporateActionsAppliedDate")]  
  40.         public long CorporateActionsAppliedDate { getset; }  
  41.   
  42.         [JsonProperty("ratingBuy")]  
  43.         public long RatingBuy { getset; }  
  44.   
  45.         [JsonProperty("ratingHold")]  
  46.         public long RatingHold { getset; }  
  47.   
  48.         [JsonProperty("ratingNone")]  
  49.         public long RatingNone { getset; }  
  50.   
  51.         [JsonProperty("ratingOverweight")]  
  52.         public long RatingOverweight { getset; }  
  53.   
  54.         [JsonProperty("ratingScaleMark")]  
  55.         public double RatingScaleMark { getset; }  
  56.   
  57.         [JsonProperty("ratingSell")]  
  58.         public long RatingSell { getset; }  
  59.   
  60.         [JsonProperty("ratingUnderweight")]  
  61.         public long RatingUnderweight { getset; }  
  62.     }  

Answers (5)