获得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;
我已经引用了 using Newtonsoft.Json.Net.dll; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Newtonsoft.Json.Converters; 为什么提示错误呢? 错误 1 当前上下文中不存在名称“JsonConvert”
string a = "{ \"access_token\":\"MNZnmcYwsJw9oc6gNVU3vmha5IRihiZBXFtxEuYQZOcoigiJXcxt6vmNucEoOgWizvEKEGgPXKrXBrCaTVerLw\", \"token_type\":\"Bearer\", \"expires_in\":432000, \"refresh_token\":\"\" } ";
var access_token = JsonConvert.DeserializeAnonymousType(a, new { access_token="" }).access_token;
using Newtonsoft.Json.Net.dll;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
为什么提示错误呢?
错误 1 当前上下文中不存在名称“JsonConvert”
Newtonsoft.Json.dll, v4.0.30319
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,是怎么回事?
取得值是:
System.Web.HttpCookie
什么意思?
看一下cookie.Value
cookie.Value = "5aaaaaaaaaa";
cookie.Expires = DateTime.Now.AddMinutes(60);
Response.AppendCookie(cookie);
把alue设成5aaaaaaaaaa 但是取出来还是这样:System.Web.HttpCookie
if (Request.Cookies["access_token"] == null)
Response.Write("no");
else
Response.Write(cookie.Value);