How to Deserialize JSON

asp.net, c#, deserialization, json, webclient

Solution

You could use json.net to do it like this:

public class AuthResponse {
    public bool LoginResult { get; set; }
}

var deserializedResponse = JsonConvert.DeserializeObject<AuthResponse>(strResult);

http://james.newtonking.com/json

Problem

I'm working on project in which I'm Posting data from asp.net webform to WCF service. I'm posting data through params and the service respond me back a `JSON string`. Now I have an issue in deserialize. I read many threads but didn't find any solution. Hope someone can sort out my problem. Thanks in Advance Response from WCF {"LoginResult":false} I just want `"false"` value. How I tried: ``` string URL = "http://localhost:32319/ServiceEmployeeLogin.svc"; WebRequest wrGETURL; wrGETURL = WebRequest.Create(URL+"/"+emp_username+"/"+emp_password+"/"+emp_type); wrGETURL.Method = "POST"; wrGETURL.ContentType = @"application/json; charset=utf-8"; HttpWebResponse webresponse = wrGETURL.GetResponse() as HttpWebResponse; Encoding enc = System.Text.Encoding.GetEncoding("utf-8"); // read response stream from response object StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc); // read string from stream data strResult = loResponseStream.ReadToEnd(); var jObj = JObject.Parse(strResult); var dict = jObj["LoginResult"].Children().Cast<JProperty>(); ```

Original source