int startIndex = html.IndexOf("{\ "access_token\":\"") + 17;
string result= html.Substring(startIndex, html.IndexOf("\",", startIndex) - startIndex);

解决方案 »

  1.   

    获得accessToken
     string a = "{ \"access_token\":\"MNZnmcYwsJw9oc6gNVU3vmha5IRihiZBXFtxEuYQZOcoigiJXcxt6vmNucEoOgWizvEKEGgPXKrXBrCaTVerLw\", \"token_type\":\"Bearer\", \"expires_in\":432000, \"refresh_token\":\"\" } ";
                var access_token = JsonConvert.DeserializeAnonymousType(a, new { access_token="" }).access_token;
      

  2.   

    我已经引用了
    using Newtonsoft.Json.Net.dll;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    using Newtonsoft.Json.Converters;
    为什么提示错误呢?
    错误 1 当前上下文中不存在名称“JsonConvert”
      

  3.   

    Newtonsoft.Json.JsonConvert
    Newtonsoft.Json.dll, v4.0.30319
      

  4.   

    麻烦看下哪里有问题?
     string content = sr.ReadToEnd();
                    string a = content;
                    var accesstoken = JsonConvert.DeserializeAnonymousType(a, new { access_token = "" }).access_token;
                    Response.Write(accesstoken);
                    HttpCookie cookie = new HttpCookie("access_token");
                    cookie.Value = accesstoken;
                    cookie.Expires = DateTime.Now.AddSeconds(60); 
                    Response.AppendCookie(cookie);
    //获取cookies
      HttpCookie cookie = Request.Cookies["access_token"];
                if (Request.Cookies["access_token"] == null)
                 Response.Write("no");
                // Response.Redirect("https://www.baidu.com/cgi-bin/login?ticket=" + cookie);
                else   
                Response.Write(cookie);无法获取cookies,是怎么回事?
      

  5.   

    AddSeconds 改成AddMinutes 试试
      

  6.   


    取得值是:
    System.Web.HttpCookie
    什么意思?
      

  7.   

    你已经取到这个cookie了
    看一下cookie.Value
      

  8.   

     HttpCookie cookie = new HttpCookie("access_token");
                    cookie.Value = "5aaaaaaaaaa";
                    cookie.Expires = DateTime.Now.AddMinutes(60);
                    Response.AppendCookie(cookie);
    把alue设成5aaaaaaaaaa  但是取出来还是这样:System.Web.HttpCookie
      

  9.   

    cookie = Request.Cookies["access_token"];
                if (Request.Cookies["access_token"] == null)
                    Response.Write("no");
                else
                    Response.Write(cookie.Value);