如何反序列化JSON

Mun*_* A. 5 c# asp.net json webclient deserialization

我正在研究我将数据从asp.net webform发布到WCF服务的项目.我通过params发布数据,服务回复了我JSON string.现在我在反序列化方面遇到了问题.我读了很多线程,但没有找到任何解决方案.希望有人能解决我的问题.提前致谢

来自WCF的回复

{ "LoginResult":假}

我只想要"false"价值.

我怎么试过:

    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>();
Run Code Online (Sandbox Code Playgroud)

hut*_*oid 6

您可以使用json.net这样做:

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

var deserializedResponse = JsonConvert.DeserializeObject<AuthResponse>(strResult);
Run Code Online (Sandbox Code Playgroud)

http://james.newtonking.com/json