1

I am calling a service and getting data like :-

var httpResponse = request.GetResponse();
using (var reader = new StreamReader(httpResponse.GetResponseStream()))
{
   text = reader.ReadToEnd();
}
JsonConvert.DeserializeObject<MyModel>();

I am facing deserialization issue because response contains data like below, data has double quotes :-

"name": "short_nme/"kfc"",
"count": "4",
"id": ""kfc""

My question is different than this because in this question the issue is serialization,mine is deserialization issues

Community
  • 1
  • 1
F11
  • 3,703
  • 12
  • 49
  • 83
  • 10
    The "right" solution in this case is a big club on the head of the programmer that created the service :-) – xanatos Feb 22 '16 at 15:50
  • 10
    Well that's just not valid JSON. Talk to whoever is producing the data. – Jon Skeet Feb 22 '16 at 15:50
  • http://stackoverflow.com/questions/8109464/json-net-deserilization-with-double-quotes appears to cover this question – C. Knight Feb 22 '16 at 16:08
  • quick solution on your end would be to replace "" with " on the whole string, but they do need to send valid json. – Filix Mogilevsky Feb 22 '16 at 16:24
  • The service is broken, and needs to be fixed. – Ben Feb 22 '16 at 16:26
  • 1
    @FilixMogilevsky this would work so long as none of the properties are empty, eg: `{ "name": "" }`; @F11: as others have mentioned the service needs to be fixed. Looks like whoever implemented it is manually creating the JSON data by naively concatenating strings instead of using a serializer... – easuter Feb 22 '16 at 16:34
  • @flix Wouldn't work. Look at `/"kfc`. They didn't simply "double" the doublequotes (like you do in SQL). They simply didn't escape them. – xanatos Feb 22 '16 at 16:52
  • thanks guys for pointing me in right direction.I am not closing the question because i think comments might be helpful. – F11 Feb 23 '16 at 14:32

0 Answers0