Because the get authorization returns a JSON string in the following format:
1 {2 ' code ': A0000,3 4 {5 ' Access_token ': access_token,//access token 6 ' expires_in ': 60,//expiry time 7 ' refresh_token ': refresh_token,//Refresh token 8 }9 }
The next step is to parse the string to get the appropriate information, such as the status code and the access token.
There are several ways to parse JSON in a. NET environment. You can hand-write a simple parser, of course, the most convenient or the use of ready-made libraries. I'm using the JavaScriptSerializer class in the System.Web.Extensions assembly.
I've never been in touch with JSON before, just like XML. Well, there's a big one. A series of articles using C language to implement a simple JSON parser have been said to be a good study, but remain in the first article. Sure enough, the best motivation for me to learn is that I have to use it before I take the initiative to learn it. Looked for a few sample code to browse a bit, and then do it yourself also has a model to achieve the purpose, do not know whether this routine is right.
First, a corresponding class is constructed based on the JSON string:
1 /// <summary>2 ///authorization Returns the result class3 /// </summary>4 [Serializable]5 [DataContract]6 Public classAuthorresult7 {8 9[DataMember (isrequired =false)]Ten PublicToken Data {Get;Set; } One A[DataMember (isrequired =false)] - Public stringCode {Get;Set; } - the[DataMember (isrequired =false)] - Public stringmsg {Get;Set; } - - +}
The Authorresult class consists of 3 attributes: Data, code, MSG. Where code represents a status code, MSG indicates a hint, and data is a custom token class that contains tokens, expiration times, refresh token properties, as defined below:
[Serializable] and [DataContract] is I refer to the code written by others, seemingly do not write can also
1 /// <summary>2 ///Token class3 /// </summary>4 Public classToken5 {6 Public stringAccess_token {Set;Get; }7 8 9 Public intexpires_in {Set;Get; }Ten One A Public stringRefresh_token {Set;Get; } - -}
Access_token, expires_in, and Refresh_token represent tokens, expiration times, and refresh tokens, respectively.
Once the corresponding class is built, you can use the deserialize<t> () generic method of the JavaScriptSerializer class to deserialize the object.
Implement video hosting callback using Iqiyi open Platform (ii)--parse to get the JSON string returned by authorization