如何使用ASP.NET解析JSON字符串?
发布时间:2020-05-28 04:43:46 所属栏目:asp.Net 来源:互联网
导读:我使用Sendgrid API发送和检索发送的邮件的统计信息.我想将API的响应存储在数据库中. protected void btnBounces_Click(object sender, EventArgs e){ try { string url = https://api.sendgrid.com/api/bounces.get.json;
|
我使用Sendgrid API发送和检索发送的邮件的统计信息.我想将API的响应存储在数据库中. protected void btnBounces_Click(object sender,EventArgs e)
{
try
{
string url = "https://api.sendgrid.com/api/bounces.get.json";
GetResult(url);
}
catch (Exception ex)
{
lblError.Text = ex.Message.ToString();
}
}
public void GetResult(string url)
{
string parameters = "api_user=xxxx&api_key=xxxx&date=1&start_date="+txtStartDate.Text+"&end_date="+txtEndDate.Text;
// Start the request
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
StreamWriter streamWriter = new StreamWriter(req.GetRequestStream());
streamWriter.Write(parameters);
streamWriter.Flush();
streamWriter.Close();
// Get the response
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader streamReader = new StreamReader(res.GetResponseStream());
string result = streamReader.ReadToEnd();
}
我将得到的回应如下: [
{
"status": "4.0.0","created": "2011-09-16 22:02:19","reason": "Unable to resolve MX host sendgrid.ne","email": "esting@sendgrid.ne"
},{
"status": "4.0.0","created": "2011-09-19 17:47:15","reason": "Connection timed out","email": "rawest@gmail.co"
}
]
如何提取四个字段中每个字段的值并将它们存储在包含四个字段的表中? 解决方法如果您不想创建Movie类,可以使用System.Web.Script.Serialization来解析并获取动态对象.JavaScriptSerializer js = new JavaScriptSerializer(); dynamic movie = js.Deserialize<dynamic>(json); (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 通过在弹性beanstalk的负载均衡器中的IIS重写到
- asp.net-mvc-3 – ASP.Net MVC 3:在哪里处理会话丢失?
- 取消选中时,ASP.NET CheckBox不会启动CheckedChanged事件
- asp.net-core – 为什么要在ASP.NET Core中使用完整的.NET
- ASP.NET MVC URL在CSS文件中自动解析
- ASP.NET两个截取字符串的方法分享
- asp.net-mvc-4 – ASP.NET Web API架构建议/反馈
- 如何从ASP.NET中的soap异常中提取内部异常?
- asp.net – 为什么有2个web.config文件
- asp.net-mvc – @Model和@model之间的区别
推荐文章
站长推荐
- asp-classic – 如何在asp经典中触发异步调用并忽
- 将ASP.Net MVC的单页添加到现有的Web窗体应用程序
- asp.net – 如何.NET网站隐藏它们的文件的.aspx扩
- asp.net – 您没有使用批量加载语句的权限
- asp.net-mvc – Razor ViewEngine HTML.Checkbox
- asp.net – iTextSharp单位
- ASP.NET中的相对路径
- asp.net – 任何人都有解决Internet上的“n项剩余
- asp.net – 如何在使用System.Web.Optimization时
- asp.net-mvc – 使用Razor,如何使所有“bool?”
热点阅读
