nvlst declared here then populated
Dictionary<string, string> nvlst = new Dictionary<string, string>();
When the service is finished, it returns
JsonConvert.SerializeObject(nvlst, Formatting.Indented)
When the client attempts to deserialize, it throws an error
alst = JsonConvert.DeserializeObject<Dictionary<string, string>>(sb.ToString());
here is the error message:
Error converting value "{
"Status": "SUCCESS:",
"CustomerId": "1",
"LicenseKey": "03bad945-37c0-4fa0-8126-fb4935df396d",
"MachineFingerPrint": "9B82-A8ED-3DE9-0D8C-26DD-2D83-C17F-C2E3",
"ExpirationDate": "11/18/2014",
"LicenseDate": "11/18/2013",
"LicenseGraceDay": "7",
"RequireRenewal": "Y",
"BaseUrl": "http://www.xxx-xxxxxxx.com",
"HelpUrl": "http://www.xxx-xxxxxxx.com/help",
"APIUrl": "http://localhost:63583/api/Ajax/runGenericMethodFromApp",
"CoName": "TestCustomer1",
"Addr1": "123 Any Street",
"Addr2": "",
"City": "Louisville",
"State": "KY",
"Zip": "40245"
}" to type 'System.Collections.Generic.Dictionary`2[System.String,System.String]'. Path '', line 1, position 704.
the actual value of the sb.ToString() is below
"\"{\\r\\n \\\"Status\\\": \\\"SUCCESS:\\\",\\r\\n \\\"CustomerId\\\": \\\"1\\\",\\r\\n \\\"LicenseKey\\\": \\\"03bad945-37c0-4fa0-8126-fb4935df396d\\\",\\r\\n \\\"MachineFingerPrint\\\": \\\"9B82-A8ED-3DE9-0D8C-26DD-2D83-C17F-C2E3\\\",\\r\\n \\\"ExpirationDate\\\": \\\"11/18/2014\\\",\\r\\n \\\"LicenseDate\\\": \\\"11/18/2013\\\",\\r\\n \\\"LicenseGraceDay\\\": \\\"7\\\",\\r\\n \\\"RequireRenewal\\\": \\\"Y\\\",\\r\\n \\\"BaseUrl\\\": \\\"http://www.xxx-xxxxxxx.com\\\",\\r\\n \\\"HelpUrl\\\": \\\"http://www.xxx-xxxxxxx.com/help\\\",\\r\\n \\\"APIUrl\\\": \\\"http://localhost:63583/api/Ajax/runGenericMethodFromApp\\\",\\r\\n \\\"CoName\\\": \\\"TestCustomer1\\\",\\r\\n \\\"Addr1\\\": \\\"123 Any Street\\\",\\r\\n \\\"Addr2\\\": \\\"\\\",\\r\\n \\\"City\\\": \\\"Louisville\\\",\\r\\n \\\"State\\\": \\\"KY\\\",\\r\\n \\\"Zip\\\": \\\"40245\\\"\\r\\n}\""
It looks like your string is getting double-serialized, so that is why it is not deserializing properly. If you are using a framework like WebAPI, it handles serialization for you, so you don't need to call
JsonConvert.SerializeObject()
. Instead, change your ApiController method to return the object directly (note that you'll need to change the method signature as well). For example: