csharp:Learn how to post JSON string to generic Handler using jQuery in ASP.Net C#.

 /// <summary>
    ///參考: http://james.newtonking.com/json/help/index.html#
    /// 塗聚文(Geovin Du) 20141228
    /// 捷為工作室
    /// </summary>
    public partial class _Default : System.Web.UI.Page
    {
        Geovindu_TimeLineProjectInfo geovindu_TimeLineProjectInfo = new Geovindu_TimeLineProjectInfo();
        Geovindu_TimeLineProjectBLL geovindu_TimeLineProjectBLL = new Geovindu_TimeLineProjectBLL();
        Geovindu_TimeLineAssetInfo geovindu_TimeLineAssetProjectInfo = new Geovindu_TimeLineAssetInfo();

        List<Geovindu_TimeLineDataInfo> selectGeovindu_TimeLineDataProject = new List<Geovindu_TimeLineDataInfo>();

        Geovindu_TimeLineDataInfo geovindu_TimeLineDataInfo = new Geovindu_TimeLineDataInfo();
        Geovindu_TimeLineAssetInfo geovindu_TimeLineAssetDataInfo = new Geovindu_TimeLineAssetInfo();

        Geovindu_TimeLineAssetBLL geovindu_TimeLineAssetBLL = new Geovindu_TimeLineAssetBLL();
        Geovindu_TimeLineDataBLL geovindu_TimeLineDataBLL = new Geovindu_TimeLineDataBLL();
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                geovindu_TimeLineProjectInfo = geovindu_TimeLineProjectBLL.SelectGeovindu_TimeLineProject(1);
                geovindu_TimeLineAssetProjectInfo = geovindu_TimeLineAssetBLL.SelectGeovindu_TimeLineAssetProject(1);
                selectGeovindu_TimeLineDataProject = geovindu_TimeLineDataBLL.SelectGeovindu_TimeLineDataProject(1);
                for (int i = 0; i < selectGeovindu_TimeLineDataProject.Count; i++)
                {
                    selectGeovindu_TimeLineDataProject[i].TimeLineDataAssetInfo = geovindu_TimeLineAssetBLL.SelectGeovindu_TimeLineAssetData(selectGeovindu_TimeLineDataProject[i].TimeDataID);
                }

                //context.Response.ContentType = "text/plain";
                //context.Response.Write("Hello World");
                geovindu_TimeLineProjectInfo = geovindu_TimeLineProjectBLL.SelectGeovindu_TimeLineProject(1);
                geovindu_TimeLineAssetProjectInfo = geovindu_TimeLineAssetBLL.SelectGeovindu_TimeLineAssetProject(1);
                selectGeovindu_TimeLineDataProject = geovindu_TimeLineDataBLL.SelectGeovindu_TimeLineDataProject(1);
                for (int i = 0; i < selectGeovindu_TimeLineDataProject.Count; i++)
                {
                    selectGeovindu_TimeLineDataProject[i].TimeLineDataAssetInfo = geovindu_TimeLineAssetBLL.SelectGeovindu_TimeLineAssetData(selectGeovindu_TimeLineDataProject[i].TimeDataID);
                }

                JObject rss =
                new JObject(
                    new JProperty("timeline",
                        new JObject(
                            new JProperty("headline", geovindu_TimeLineProjectInfo.TimeHeadline),
                            new JProperty("type", geovindu_TimeLineProjectInfo.TimeType),
                            new JProperty("text", geovindu_TimeLineProjectInfo.TimeText),
                            new JProperty("startDate", geovindu_TimeLineProjectInfo.TimeStartDate.ToString("yyyy,MM,dd")),
                            new JProperty("asset",
                                new JObject(
                                     new JProperty("media", geovindu_TimeLineAssetProjectInfo.TimeAssetMedia),
                                     new JProperty("credit", geovindu_TimeLineAssetProjectInfo.TimeAssetCredit),
                                     new JProperty("caption", geovindu_TimeLineAssetProjectInfo.TimeAssetCaption))),
                                     new JProperty("date",
                                    from p in selectGeovindu_TimeLineDataProject
                                    orderby p.TimeDataHeadline
                                    select new JObject(
                                        new JProperty("startDate", p.TimeDataStartDate.ToString("yyyy,MM,dd")),
                                        new JProperty("headline", p.TimeDataHeadline),
                                        new JProperty("text", p.TimeDataText),
                                        new JProperty("asset",
                                            new JObject(
                                        //geovindu_TimeLineAssetDataInfo=geovindu_TimeLineAssetBLL.SelectGeovindu_TimeLineAssetData(p.TimeDataID)
                                                 new JProperty("media", p.TimeLineDataAssetInfo.TimeAssetMedia),
                                                 new JProperty("credit", p.TimeLineDataAssetInfo.TimeAssetCredit),
                                                 new JProperty("caption", p.TimeLineDataAssetInfo.TimeAssetCaption)

                                                )))))));
                Response.Write(rss.ToString());
                File.WriteAllText(Server.MapPath("geovindu.json"), rss.ToString());

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message.ToString());
            }

        }
    }
}
时间: 2025-01-15 01:25:26

csharp:Learn how to post JSON string to generic Handler using jQuery in ASP.Net C#.的相关文章

You&#39;re trying to decode an invalid JSON String JSON返回有解析问题

SpringMVC架构的web程序,通常用map返回消息在浏览器中显示,但是实际中报下列错误“”You're trying to decode an invalid JSON String“返回的字符串的被加入了<pre></pre>, 解决方法,在springMvc的配置文件中加入以下配置: <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdap

服务器返回一个无效的JSON string,处理

使用AFN,服务端返回的结果看看哪里错了. 因为后台返回的不是一个有效的JSON string 所以库里面转化的时候一个error就抛出了.所以这时候,就自己做解析好了. NSLog ( @"operation: %@" , operation. responseString );

ExtJS4.1.1 Uncaught Ext.JSON.decode(): You&#39;re trying to decode an invalid JSON String的问题

上传文件之后出现 Uncaught Ext.JSON.decode(): You're trying to decode an invalid JSON String可能是由于因为你没有返回内容,或者是因为没有后面的两句代码,就是没有写入输出流中. outs.write("{success:true}"); outs.flush(); outs.close(); 我之前一直报错就是因为没有outs.flush(); outs.close();这两句 ExtJS4.1.1 Uncaugh

Convert JS object to JSON string

Modern browsers (IE8, FF3, Chrome etc.) have native JSON support built in (Same API as with JSON2). So as long you're not dealing with IE6/7 you can do it just as easily as that: var j={"name":"binchen"}; JSON.stringify(j); // '{"

FastJSON 简介及其Map/JSON/String 互转

在日志解析,前后端数据传输交互中,经常会遇到 String 与 map.json.xml 等格式相互转换与解析的场景,其中 json 基本成为了跨语言.跨前后端的事实上的标准数据交互格式.应该来说各个语言中 解析 json 的库都一大片(具体 json 格式与三方库的介绍请见:http://www.json.org/json-zh.html),比如 python 都集成在了内置库中,成为标准 API,今天我们要聊的是 java 中如何方便的使用 json 格式. 从上面的链接介绍中我们可以看到,

ES5新增函数之一: Array, JSON, String, Date

ES5即ECMAScript 5.1,在JavaScript语言基础之上添加了很多新的特性,对现有的对象和语句进行相应的增强和规范,主要包括一些新增函数.对象类型增强,以及严格模式编程规范. 今天我们先来介绍以下几个新增的函数: Array.isArray(obj); Array.prototype.forEach(); Array.prototype.indexOf(); Array.prototype.lastIndexOf(); Array.prototype.filter(); Arra

convert NameValueCollection/Dictionary&lt;string, object&gt; to JSON string

var col=HttpContext.Current.Request.Form; Dictionary<string, object> dict = new Dictionary<string, object>(); foreach (var key in col.AllKeys) { //dict.Add(k, col[k]); string[] values = col.GetValues(key); if (values.Length == 1) { dict.Add(ke

如果一个json string中含有“class”这个key, 那么利用JSONObjec.fromObject(string)得到的一个json object会丢失“class”信息

查看net.sf.json.JSONObject的source code, 发现JSONObject.fromObject()的内部 有这样的处理:如果json key是"class",那么这个json object不添加这个property. 解决办法: 1. 修改source code 2. 用Gson, json.simple等代替JSONObject

通过 SuperObject 生成 json string

(* { "name": "Henri Gourvest", /* this is a comment */ "vip": true, "telephones": ["000000000", "111111111111"], "age": 33, "size": 1.83, "adresses": [ { "adres