1

i have written code in wcf to fetch data from sql database . Following is my code

string SP_STATE = "SP_STATE";
Select selectOBJ = new Select();
DataTable dt = selectOBJ.selectSTATE(SP_STATE);
string jsonData= JsonConvert.SerializeObject(dt);
return jsonData;

i have written code in asp.net to fetch data from wcf post service which is added as a service reference but when i am calling from service ..it is giving me error(Additional information: There was an error deserializing the object of type System.String. End element 'root' from namespace '' expected. Found element 'GetStateListResult' from namespace '')

following is my code

MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(doctorServiceObj.GetStateList()));
STATELISTRESULT objStudent = (STATELISTRESULT)jsonSer.ReadObject(stream);
Response.Write(string.Format("Name = {0} and Address = {1}", objStudent.STATE, objStudent.ROW_ID));

Please Suggest me solution

Sourav Sharma
  • 277
  • 3
  • 13
  • Possible duplicate of [How to perform serialization and deserialization of datatables to and from JSON](http://stackoverflow.com/questions/13165712/how-to-perform-serialization-and-deserialization-of-datatables-to-and-from-json) – Ricardo Pontual Nov 21 '16 at 12:30

1 Answers1

0

please try this at server side:

    MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject( doctorServiceObj.GetStateList())));

then you can deserilze it in client side like this:

var response = Newtonsoft.Json.JsonConvert.DeserializeObject<YourType>(responseString);
Mohammad
  • 2,724
  • 6
  • 29
  • 55
  • I facing the same error, can you explain me what is YourType and responseString. I'm serelizing DataTable from WCF is YoutType is going to be DataTable. – Rajiv Choudhary Nov 21 '16 at 13:56