作者:强伟2502859647 | 来源:互联网 | 2023-09-14 10:05
源码下载,Newtonsoft.Json.Net35.dll下载usingSystem.Data;usingNewtonsoft.Json;usingNewton
源码下载,Newtonsoft.Json.Net35.dll下载
using System.Data;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;using System.Net;
using System.Text;namespace Utility
{/// /// JsonHelper 需引用Newtonsoft.Json.Net35.dll/// public class JsonHelper{#region ASP.NET DataTable 与Json互转/// /// DataTable 转换为 Json 格式的字符串(需引用Newtonsoft.Json.Net35.dll)/// /// /// public static string DataTableFormatToJson(DataTable dt){string json = JsonConvert.SerializeObject(dt, new DataTableConverter());return json;}/// /// Json 格式字符串转换为 DataTable(需引用Newtonsoft.Json.Net35.dll)/// /// /// public static DataTable JsonFormatToDataTable(string json){DataTable tb = (DataTable)JsonConvert.DeserializeObject(json, typeof(DataTable));return tb;}#endregion/// /// http请求URL,获取返回的Json信息/// /// /// public static string HttpGetJson(string url){WebClient wc = new WebClient();wc.Credentials = CredentialCache.DefaultCredentials;wc.Encoding = Encoding.UTF8;string returnText = wc.DownloadString(url);if (returnText.Contains("errcode")){//可能发生错误}return returnText;}}
}