0

I'm creating an HttpResponseMessage object and sending it back to the caller. I also pass in a Dictionary<string,object>.

return HttpContext.Current.Request.CreateResponse(httpStatusCode.Ok, mydict);

How does the caller access the dictionary on their end? They get back the HttpResponseMessage type but trying to read the Content object on it hasn't produce anything like a dictionary.

4thSpace
  • 43,672
  • 97
  • 296
  • 475
  • What has it produces? Can you show the result? If the content-type is JSON, then it will not look like a dictionary. See [this](http://stackoverflow.com/questions/1207731/how-can-i-deserialize-json-to-a-simple-dictionarystring-string-in-asp-net) – Michael Jul 19 '16 at 20:37
  • Is the caller another .net app? Or an ajax call? Serializing a dictionary won't really result in the type of object you might expect. – agriffin Jul 19 '16 at 22:05
  • No JSON but I see now the dictionary is flattened into a string when I use Content.ReadAsStringAsync().Result. I believe I just need to serialize the string back into a dictionary? The caller is a .net client app. – 4thSpace Jul 19 '16 at 22:06
  • Yeah the normal way is to deserialize the string back into a dictionary but since you are using an "object" as the dictionary value you may run into some issues because the deserializer will not know what kind of object it is deserializing. However, if you are only using string values (or any other type not ambiguous) then you will be ok. – agriffin Jul 19 '16 at 22:21

0 Answers0