Regionhttp request, get the JsonObject object, get the JsonObject object, TheresultsjsonRequestURL # region http request, get the JsonObject object
///
<
Summary
>
///
Get JsonObject
///
<
/
Summary
>
///
<
Returns
>
The results json.
<
/
Returns
>
///
<
Param
Name
=
"
RequestUrl
"
>
Request URL.
<
/
Param
>
Public static JsonObject ParseResultsJson (object requestUrl)
{
HttpWebResponse httpRes = GetRequestInfo (requestUrl );
If (httpRes = null)
Return null;
Using (Stream s = httpRes. GetResponseStream ()){
Return (JsonObject) JsonObject. Load (s );
}
}
///
<
Summary
>
///
Get Request Url Information by request method type "get"
///
<
/
Summary
>
///
<
Param
Name
=
"
RequestUrl
"
>
Request URL.
<
/
Param
>
Public static HttpWebResponse GetRequestInfo (object requestUrl)
{
If (! Utils. Tools. IsConnect ()){
// If it is offline, null is returned directly.
Return null;
}
Try {
HttpWebRequest httpReq = (HttpWebRequest) HttpWebRequest. Create (new Uri (requestUrl. ToString ()));
HttpReq. ContentType = "application/json ";
HttpReq. Method = "GET ";
Using (HttpWebResponse httpRes = (HttpWebResponse) httpReq. GetResponse ()){
Return httpRes;
}
} Catch (Exception e ){
Utils. Tools. AppendToLog ("xxxxx. MyTestVC. GetRequestInfo ()", e. Message + "\ r \ n ");
Return null;
}
}
# Endregion
Code call:
/// <Summary>
///Obtain information list data
/// </Summary>
/// <Returns>The items.</Returns>
Public static List GetArticleList (bool isrefresh = false)
{
If (isrefresh)
NSUserDefaults. StandardUserDefaults. RemoveObject (KeyCenter. Key_NewsList );
String _ url = string. Format (Utils. UrlCenter. UrlNewsList, "10", HttpUtility. UrlDecode (" "));
JsonObject j = CacheHelp. ParseResultsJson (_ url );
If (j! = Null ){
Var results = (from t in (JsonArray) j ["articleInfoList"]
Let r = t as JsonObject
Select new ArticleModel {
Articleid = t ["Articleid"],
Articletitle = t ["Articletitle"],
ArticleContent = t ["articleContent"],
Articlechannel = t ["Articlechannel"],
Articlecreatedate = t ["Articlecreatedate"],
Articleimg = t ["Articleimg"],
ArticleAuthor = t ["ArticleAuthor"],
Outline = t ["outline"],
ClickNumber = t ["clicknumber"]
}). ToList ();
Return results;
} Else {
Utils. Tools. Alert ("failed to get data! ");
Return null;
}
}