Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am serializing objects in cloud server in the web role:

C#
using Newtonsoft.Json;    
string returnJsonMessage = JsonConvert.SerializeObject(returnMessage);


On the client side:

C#
BaseResponseDeviceMessage retVal = null;
var req = HttpWebRequest.Create(@reqString);
req.Method = requestMethod;
req.ContentLength = 0;
req.ContentType = @"application/json";

string jsonResp = "";
try
{
    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
    using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
    {
        jsonResp = sr.ReadToEnd();
    }

    string t = JsonConvert.DeserializeObject<string>(jsonResp);
    retVal = JsonConvert.DeserializeObject<T>(t);

}


You can see that in order to get my message back, I need to DeSerialize twice. Why? how can this problem be solved? Thank you all, and a good day.
Posted
Updated 12-May-13 20:05pm
v3
Comments
StM0n 13-May-13 2:08am    
Have you checked the jsonResp-String? Are there any double quotes (I ran into some similar problems)?
tallybh1 13-May-13 4:23am    
No, there are no double quotes.
StM0n 13-May-13 4:45am    
Then I have to admit I have the same problem... a possible solution would be replacing the double quotes... but maybe someone else has a better idea :)
tumbledDown2earth 15-May-13 0:41am    
Hmm escaping '"' character can help. But let me try, Can you share a sample json like yours?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900