This question is different from the one suggested by the mod. because I am returning a string and not an object here.
I am attempting to send a json string back to the client. However it is invalid (the formatting is incorrect) any suggestions on how I can fix this ?
This is the server side
[HttpGet]
public string foo()
{
Dictionary<string, string> response = new Dictionary<string, string>();
response["itemID"] = "ABC";
return JsonConvert.SerializeObject(response);
}
and on the client side I am doing this
using (WebClient client = new WebClient())
{
string clientResponse = client.DownloadString(url);
Dictionary<string, string> response = JsonConvert.DeserializeObject<Dictionary<string, string>>(clientResponse);
}
clientRepsonse is apparently not properly formatted json its like this (shown below). Thats why it cannot be de-searialized
"{\"itemID\":\"ABC\"}"
Any suggestions on how I can fix this.
In the locals in visual studio it looks like this "\"{\\\"itemID\\\":\\\"ABC\\\"}\""
And in preview it looks like this
"{\"itemID\":\"ABC\"}"