C# 在C中反序列化JSON格式的POST数据#

C# 在C中反序列化JSON格式的POST数据#,c#,.net,json,post,C#,.net,Json,Post,我需要在C#中捕获/反序列化,只使用内置的.NET库,从JavaScript文件接收JSON格式的POST数据 JSON格式为: {"URLs":[{"url_name":"Google", "url_address":"http://www.google.com/"}, {"url_name":"Yahoo", "url_address":"http://www.yahoo.com/"},{"url_name":"FB", "url_address":"http://www.fb.com/"}

我需要在C#中捕获/反序列化,只使用内置的.NET库,从JavaScript文件接收JSON格式的POST数据

JSON格式为:

{"URLs":[{"url_name":"Google", "url_address":"http://www.google.com/"}, {"url_name":"Yahoo", "url_address":"http://www.yahoo.com/"},{"url_name":"FB", "url_address":"http://www.fb.com/"},{"url_name":"MegaSearches", "url_address":"http://www.megasearches.com/"}]}

JavaScript文件在中发布JSON数据,我需要在C#中的.aspx代码中捕获JSON数据并保存到数据库。

首先,创建类来保存URL数据,如下所示:

public class UrlData
{
    public List<Url> URLs {get;set;}
}

public class Url
{
    public string url_address {get;set;}
    public string url_name {get;set;}
}
UrlData theUrlData = new JavaScriptSerializer().Deserialize<UrlData>(jsonResult);
公共类UrlData
{
公共列表URL{get;set;}
}
公共类Url
{
公共字符串url_地址{get;set;}
公共字符串url_name{get;set;}
}
现在可以将JSON数据反序列化到对象中,如下所示:

public class UrlData
{
    public List<Url> URLs {get;set;}
}

public class Url
{
    public string url_address {get;set;}
    public string url_name {get;set;}
}
UrlData theUrlData = new JavaScriptSerializer().Deserialize<UrlData>(jsonResult);
UrlData theUrlData=newJavaScriptSerializer()。反序列化(jsonResult);

注意:
jsonResult
是从获取数据的位置返回的JSON数据。

为传入的JSON数据创建一个视图模型类。
public class UrlHelper {
    public string url_name {get;set;}
    public string url_address {get;set;}
}

在代码隐藏的方法中,让post方法接受数据。
public YourJsonFormPost(List<UrlHelper> URLs){
    //do your work 
}
publicYourJSonFormPost(列出URL){
//做你的工作

}

非常感谢您的快速回复。你知道如何使用C#?@Ali007“SqlBulkCopy”SQL数据库中的“url”吗?不知道,我建议你开始一个新的问题,专门询问这个问题,因为你会有一个特定于SQL的标记。如何将JSON格式的POST数据捕获为字符串[“jsonResult”字符串]在C#从JavaScript文件接收的情况下?如何在C#从JavaScript文件接收的情况下将JSON格式的POST数据捕获为字符串?如何在C#从JavaScript文件接收的情况下将JSON格式的POST数据捕获为字符串?