C# convert string to dictionary
c#, dictionary, string, system.net
Solution
If you add a package like Newtonsoft's Json to your project, you can deserialize the Json in to an anonymous type. You can then fetch the url from that. This is available via NuGet within Visual Studio and provides support for async or sync serialization/deserialization.
public string GetUrl(string bitlyResponse)
{
var responseObject = new
{
data = new { url = string.Empty },
};
responseObject = JsonConvert.DeserializeAnonymousType(bitlyResponse, responseObject);
return responseObject.data.url;
}
Problem
I get this response string from the Bitly api: ``` { "status_code": 200, "status_txt": "OK", "data": { "long_url": "http:\/\/amazon.de\/", "url": "http:\/\/amzn.to\/1mP2o58", "hash": "1mP2o58", "global_hash": "OjQAE", "new_hash": 0 } } ``` How do I convert this string to a dictionary and how do I access the value for the key `"url"` (without all the `\`)