ASP.NET 操作json

用到第三方类库Newtonsoft.Json.dll

#region  将datatable转为json
        /// <summary>
        /// 返回回JSON数据到
        /// </summary>
        /// <param name="dt">数据表</param>
        /// <returns>JSON字符串</returns>   
        /// <author>ccc</author>
        /// <createtime>2013-09-17</createtime>
        /// <remarks></remarks>
        private string CreateJsonParameters(DataTable dt)
        {
            string result = "";
           
            result = JsonConvert.SerializeObject(dt, new DataTableConverter());
            return result;
        }
        #endregion
将datatable转为json
/// <summary>
    /// 用于接收json
    /// </summary>
    public class newsJosn
    {
        public string webUrl { get; set; }
        public string webTitle { get; set; }
        public string webKeyWord { get; set; }
        public string webDescription { get; set; }
    }

newsJosn deserializedProduct = JsonConvert.DeserializeObject<newsJosn>(jsonArr);
                    NewsInfo newsInfo = new NewsInfo();
                    newsInfo.Title = deserializedProduct.webTitle;
                    newsInfo.SourceURL = deserializedProduct.webUrl;
                    newsInfo.Contents = deserializedProduct.webKeyWord;

多条需要循环jsonArr改为jsonArr[i]

原文地址:https://www.cnblogs.com/SacredSX/p/3328576.html