日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

c#自定义Json类

發布時間:2024/6/21 C# 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c#自定义Json类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

類名:

public class Messageback
{
public string errcode { get; set; }
public string errmsg { get; set; }
}

public class MessageInfo
{
public string touser { get; set; }
//public string toparty { get; set; }
public string msgtype { get; set; }
public string agentid { get; set; }
public List<Txt_content> text { get; set; }
}
public class NewsInfo
{
public string touser { get; set; }
public string msgtype { get; set; }
public string agentid { get; set; }
public string news { get; set; }
}

public class news_articles
{
public List<articles_info> articles { get; set; }
}

public class articles_info
{
public string title { get; set; }
public string description { get; set; }
public string url { get; set; }
public string picurl { get; set; }
}

public class Txt_content
{
public string content{get;set;}
}

?

方法:

protected void QunFa_Click(object sender, EventArgs e)
{
MessageInfo msinfo = new MessageInfo();
int Row = this.CheckBoxList1.Items.Count;
int snum = 0;
int fnum = 0;
string OpenID, Agentname, PostData1, PostData2, NewPostData,ToUser;
ArrayList suclist = new ArrayList();
ArrayList faillist = new ArrayList();
for(int i=0;i<Row ;i++)
{
if(this.CheckBoxList1.Items[i].Selected == true)
{
msinfo.touser = this.CheckBoxList1.Items[i].Value;
Agentname = this.CheckBoxList1.Items[i].Text;
msinfo.agentid = "28";
Txt_content txt = new Txt_content { content = Content.Text };
List<Txt_content> list = new List<Txt_content>();
list.Add(txt);
msinfo.text = list;
msinfo.msgtype = "text";
string res = "";
string Access_Token = IsExistAccess_Token();

string posturl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + Access_Token;
string postData = JsonConvert.SerializeObject(msinfo);
PostData1 = postData.Replace("[", "");
PostData2 = PostData1.Replace("]", "");
res = GetPage(posturl, PostData2);
//微信消息返回處理
JObject msgback = JObject.Parse(res);
//Response.Write(res);
int suc = Convert.ToInt32(msgback["errcode"].ToString());
if(suc==0)
{
suclist.Add(Agentname);
snum = snum + 1;
}
else
{
faillist.Add(Agentname);
fnum = fnum + 1;
}
}
}
txtalert.InnerHtml = "<b>共" + snum + "名員工短信發送成功! "+ fnum +"名發送失敗!</b><br/>";
//輸出人員名單
txtalert.InnerHtml += "<b>發送成功人員名單:</b><br/>";
int snum_temp = 0;
foreach (string suclist_temp in suclist)
{
//標點符號處理
snum_temp = snum_temp + 1;
if(snum_temp==suclist.Count)
{
txtalert.InnerHtml += suclist_temp;
}
else
{
txtalert.InnerHtml += suclist_temp;
txtalert.InnerHtml += ",";
}

}
txtalert.InnerHtml += "<br/><b>發送失敗人員名單:</b><br/>";
int fnum_temp = 0;
foreach (string faillist_temp in faillist)
{
//標點符號處理
fnum_temp = fnum_temp + 1;
if(fnum_temp==faillist.Count)
{
txtalert.InnerHtml += faillist_temp;
}
else
{
txtalert.InnerHtml += faillist_temp;
txtalert.InnerHtml += ",";
}

}
//alert.InnerHtml += "<br/>成功人員名單:"+ +"。<br/>失敗人員名單:"+ faillist.ToString() +"";
//Response.Write("共有" + num + "名員工短信發送成功!");
}

protected void tuwen_Click(object sender, EventArgs e)
{
NewsInfo newsinfo = new NewsInfo();
news_articles news_art = new news_articles();
articles_info art_info = new articles_info();
ArrayList suclist = new ArrayList();
ArrayList faillist = new ArrayList();
int Row = this.CheckBoxList1.Items.Count;
int snum = 0;
int fnum = 0;
string tt = this.title.Text;
string des = this.descrip.Text;
string url = this.url.Text;//圖文鏈接
string picurl = this.picurl.Text;//封面圖片
int num = 0;
string OpenID, PostData1, PostData2, Agentname;
for (int i = 0; i < Row; i++)
{
if (this.CheckBoxList1.Items[i].Selected == true)
{
Agentname = this.CheckBoxList1.Items[i].Text;
newsinfo.touser = this.CheckBoxList1.Items[i].Value;
newsinfo.msgtype = "news";
newsinfo.agentid = "28";
//art_info.title = Agentname + "同學,今天是你的生日,祝你生日快樂~!";
art_info.title = tt;
art_info.description = des;
art_info.url = url;
art_info.picurl = picurl;
List<articles_info> list = new List<articles_info>();
list.Add(art_info);
news_art.articles = list;
newsinfo.news = JsonConvert.SerializeObject(news_art).Replace("\\","");
string res = "";
string Access_Token = IsExistAccess_Token();
string postData = JsonConvert.SerializeObject(newsinfo);
PostData1 = postData.Replace("\"[", "[");
PostData2 = PostData1.Replace("]\"", "]");
PostData2 = PostData2.Replace("\":\"{", "\":{");
PostData2 = PostData2.Replace("}\"}", "}}");
PostData2 = PostData2.Replace("\\", "");
string posturl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + Access_Token;
//string postData = "{\"touser\":\"" + OpenID +"\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\""+ tt +"\",\"description\":\""+ des +"\",\"url\":\""+ url +"\",\"picurl\":\""+ picurl +"\"}]}";
res = GetPage(posturl,PostData2);

JObject msgback = JObject.Parse(res);
//Response.Write(res);
int suc = Convert.ToInt32(msgback["errcode"].ToString());
if (suc == 0)
{
suclist.Add(Agentname);
snum = snum + 1;
}
else
{
faillist.Add(Agentname);
fnum = fnum + 1;
}
}

}
newsalert.InnerHtml = "<b>共" + snum + "名員工圖文消息發送成功! " + fnum + "名發送失敗!</b><br/>";
//輸出人員名單
newsalert.InnerHtml += "<b>發送成功人員名單:</b><br/>";
int snum_temp = 0;
foreach (string suclist_temp in suclist)
{
//標點符號處理
snum_temp = snum_temp + 1;
if (snum_temp == suclist.Count)
{
newsalert.InnerHtml += suclist_temp;
}
else
{
newsalert.InnerHtml += suclist_temp;
newsalert.InnerHtml += ",";
}

}
newsalert.InnerHtml += "<br/><b>發送失敗人員名單:</b><br/>";
int fnum_temp = 0;
foreach (string faillist_temp in faillist)
{
//標點符號處理
fnum_temp = fnum_temp + 1;
if (fnum_temp == faillist.Count)
{
newsalert.InnerHtml += faillist_temp;
}
else
{
newsalert.InnerHtml += faillist_temp;
newsalert.InnerHtml += ",";
}

}
}

轉載于:https://www.cnblogs.com/pp521/p/4943029.html

總結

以上是生活随笔為你收集整理的c#自定义Json类的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。