Hi,
I have a requirement to get some data from db using WebAPI and send back to user as a JSON string and convert back it to a datatable. I could not find out what is going wrong. Please suggest.
JSON string
-----------------
"[{\"TestID\":\"1 \",\"WorkOrderID\":\"2 \",\"Recipe\":\"1110 \",\"FitCoeffA\":\"0 \",\"FitCoeffB\":\"0 \",\"FitCoeffC\":\"0 \",\"Temp0\":\"0 \",\"Temp1\":\"0 \",\"Temp2\":\"0 \",\"TestResult\":\"1 \"},{\"TestID\":\"1 \",\"WorkOrderID\":\"2 \",\"Recipe\":\"1110 \",\"FitCoeffA\":\"0 \",\"FitCoeffB\":\"0 \",\"FitCoeffC\":\"0 \",\"Temp0\":\"0 \",\"Temp1\":\"0 \",\"Temp2\":\"0 \",\"TestResult\":\"1 \"}]"
Exception
----------
Unexpected JSON token when reading DataTable. Expected StartArray, got String. Path '', line 1, position 557.
Error stack trace
--------------------
at Newtonsoft.Json.Converters.DataTableConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, 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.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type)
at iMFCTest.Service.iMFCDAL.<getcalibrationdata>d__3.MoveNext() in C:\Users\20063692\source\Workspaces\E-07430-01-01\Solution\iMFCTest\iMFCTest.Service\iMFCDAL.cs:line 61
What I have tried:
I used below code for conversion:
DataTable table=(DataTable)JsonConvert.DeserializeObject(dataString, (typeof(DataTable)));