Serializing - Deserializing Dictionary

Nov 27, 2014 at 6:39 PM
So I have a Dictionary<string, string>, I serialize it on one end, the go to deserialize on the other, but it always fails with:

Unable to cast object of type 'System.String' to type 'System.Collections.Generic.Dictionary`2[System.String,System.String]'.

This is an example of the return that I've pared down for simplicity to test, but it still won't deserialize this.

"\"{\\"includeLabel\\":\\"True,False\\"}\""

If I break and manually change this to, "{'includeLabel':'True,False'}" before it tries to deserialize it, it works.

So I added,
string resp = GetResponse("WebAPI URL Here");

            __resp = resp.Replace("\\", "");
            resp = resp.Substring(1, resp.Length - 1);
            resp = resp.Substring(0, resp.Length - 1);__

            Dictionary<string, string> barcodeParams = JsonConvert.DeserializeObject<Dictionary<string, string>>(resp);
Which gets deserialized correctly. Is this something that can be accounted for in settings without having to throw that specific code at it?