Beispiel #1
0
 public string GetComments(int id)
 {
     List<string> comments = new List<string>();
     comments.Add("comment 1");
     comments.Add("comment 2");
     var x = new { Post = id, Comments = comments };
     return x.ToJsonString();
 }
        public void ToJsonString_On_Object_Collection_Serializes_To_Json_Array()
        {
            IEnumerable<object> objectCollection = new[] { new { member = "value1" }, new { member = "value2" } };

            string expected = @"[{""member"":""value1""},{""member"":""value2""}]";

            string objectCollectionSerialized = objectCollection.ToJsonString();

            Assert.AreEqual(expected, objectCollectionSerialized);
        }
        public void ToJsonString_On_Object_Serializes_To_Json_String()
        {
            object nonNullObject = new { member1 = "value1", member2 = "value2" };

            string expected = @"{""member1"":""value1"",""member2"":""value2""}";

            string nonNullObjectSerialized = nonNullObject.ToJsonString();

            Assert.AreEqual(expected, nonNullObjectSerialized);
        }
        public JsonResult Delete(HiveId id)
        {
            Mandate.ParameterNotEmpty(id, "id");

            using (var uow = BackOfficeRequestContext.Application.Hive.OpenWriter<IContentStore>())
            {
                uow.Repositories.Schemas.Delete<AttributeType>(id);
                uow.Complete();
            }
            
            //return a successful JSON response

            Notifications.Add(new NotificationMessage("Delete.Successful".Localize(this), NotificationType.Success));            
            var obj = new { message = "Success", notifications = Notifications };
            return new CustomJsonResult(() => obj.ToJsonString());
        } 
Beispiel #5
0
        public string Excute(WeChatConfig config, WeChatData data)
        {
            //var msg = new
            //{
            //    button = new object[]
            //    {
            //        new {type="click",name="定位监控",key="CLICK_DWJK" },
            //        new {type="click",name="里程报表",key="CLICK_LCBB" },
            //        new
            //        {
            //            name="账号",
            //            sub_button=new object[]
            //            {
            //                new {type="click",name="绑定账号",key="CLICK_BDZH" },
            //                new {type="click",name="取消绑定",key="CLICK_QXBD" }
            //            }
            //        }
            //    }
            //};

            var msg = new
            {
                button = new object[]
                {
                    new
                    {
                        name="查车",
                        sub_button=new object[]
                        {
                              new {type="click",name="定位监控",key="CLICK_DWJK" },
                              new {type="click",name="里程报表",key="CLICK_LCBB" }
                        }
                    },
                    new {type="click",name="设防撤防",key="CLICK_SFCF" },
                    new
                    {
                        name="账号",
                        sub_button=new object[]
                        {
                            new {type="click",name="绑定账号",key="CLICK_BDZH" },
                            new {type="click",name="取消绑定",key="CLICK_QXBD" }
                        }
                    }
                }
            };

            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem();
            item.URL = string.Format("{0}menu/create?access_token={1}", config.APIUrl, config.AccessToken);
            item.Method = "POST";
            item.Encoding = "utf-8";
            item.ContentType = "application/x-www-form-urlencoded";
            item.Postdata = msg.ToJsonString();
            string result = http.GetHtml(item);
            return result;
        }