I am trying to do a POST and then read the JSON response in a string.
I believe my problem is that I need to pass my own object to the DataContractJsonSerializer, but I am wondering if there is any way to just get the response into an associative array or some kind of key / value format.
My JSON has the following format: {"license": "AAAA-AAAA-AAAA-AAAA"}, and my code looks like this:
using (Stream response = HttpCommands.GetResponseStream(URL, FormatRegistrationPost(name, email))) { string output = new StreamReader(response).ReadToEnd(); response.Close(); DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(string)); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(output)); string results = json.ReadObject(ms) as string; licenseKey = (string) results.GetType().GetProperty("license").GetValue(results, null); }
source share