here my JSON string
final1 = [{"Col1":"219","Col2":"234","Col3":"79","Col4":"12","Col5":"0D2","Col6":"14","Col7":"35","Col8":"null","NUMB":"[{"PPWK":"201710","Vol":0},{"PPWK":"201711","Vol":0},{"PPWK":"201712","Vol":0},{"PPWK":"201713","Vol":0}]"}]
We are getting error when do Deserialise the JSON string.
DynamicJsonCollection = JsonConvert.DeserializeObject<List<marketdata>>(final1);
Error:
Newtonsoft.Json.JsonSerializationException was unhandled by user code
HResult=-2146233088
Message=Error converting value "[{" to type 'System.Collections.Generic.List`1[WPFJSON.Numb]'. Path '[0].NUMB', line 1, position 105.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
at WPFJSON.ViewModel..ctor() in c:\Users\gsubram2\Documents\Visual Studio 2012\Projects\WPFJSON\WPFJSON\ViewModel.cs:line 67
at WPFJSON.MainWindow..ctor() in c:\Users\gsubram2\Documents\Visual Studio 2012\Projects\WPFJSON\WPFJSON\MainWindow.xaml.cs:line 34
InnerException: System.ArgumentException
HResult=-2147024809
Message=Could not cast or convert from System.String to System.Collections.Generic.List`1[WPFJSON.Numb].
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)
at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
InnerException:
What I have tried:
We have tried it as below
DynamicJsonCollection = JsonConvert.DeserializeObject<List<marketdata>>(final1);