当前位置: 首页>>代码示例>>C#>>正文


C# JsonSerializer.DeserializeFromString方法代码示例

本文整理汇总了C#中JsonSerializer.DeserializeFromString方法的典型用法代码示例。如果您正苦于以下问题:C# JsonSerializer.DeserializeFromString方法的具体用法?C# JsonSerializer.DeserializeFromString怎么用?C# JsonSerializer.DeserializeFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonSerializer的用法示例。


在下文中一共展示了JsonSerializer.DeserializeFromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetChannelHistory

        public GroupsHistoryResponseModel GetChannelHistory(string slackApiToken, string channel, DateTime startTime, DateTime endTime, int count)
        {
            var responseString = "https://slack.com/api/channels.history"
                .PostUrlEncodedAsync(
                    new
                    {
                        token = slackApiToken,
                        channel,
                        latest = endTime.ToUnixTime(),
                        oldest = startTime.ToUnixTime(),
                        count
                    })
                .ReceiveString()
                .Result;

            var serializer = new JsonSerializer<GroupsHistoryResponseModel>();
            var response = serializer.DeserializeFromString(responseString);

            if (!response.ok)
            {
                throw new SlackApiException(response.error);
            }

            return response;
        }
开发者ID:prinzo,项目名称:Attack-Of-The-Fines-TA15,代码行数:25,代码来源:ChannelApi.cs

示例2: GetAllMemberInformation

        public MembersResponse GetAllMemberInformation()
        {
            var responseString = "https://slack.com/api/users.list"
                                .PostUrlEncodedAsync(new { token = ConfigurationManager.AppSettings["BotKey"] })
                                .ReceiveString().Result;

            var serializer = new JsonSerializer<MembersResponse>();
            var memberInfo = serializer.DeserializeFromString(responseString);

            return memberInfo;
        }
开发者ID:prinzo,项目名称:Attack-Of-The-Fines-TA15,代码行数:11,代码来源:MemberInfoApi.cs

示例3: Can_serialize_and_deserialize_text_email

        public void Can_serialize_and_deserialize_text_email()
        {
            var serializer = new JsonSerializer<EmailMessage>();
            var email = MessageFactory.EmailWithText(1).Single();
            var json = serializer.SerializeToString(email);
            Assert.IsNotNull(json);
            
            Console.WriteLine(json);

            var deserialized = serializer.DeserializeFromString(json);
            Assert.IsNotNull(deserialized);
        }
开发者ID:ehsan-davoudi,项目名称:webstack,代码行数:12,代码来源:EmailSerializerTests.cs

示例4: Install

        public static void Install()
        {
            JsConfig<Stack<CallerContext>>.RawDeserializeFn = s =>
            {
                var jsonSerializer = new JsonSerializer<List<CallerContext>>();
                var callerContexts = jsonSerializer.DeserializeFromString(s);
                callerContexts.Reverse();
                return new Stack<CallerContext>(callerContexts);
            };

            JsConfig.DateHandler = JsonDateHandler.ISO8601;
        }
开发者ID:petxo,项目名称:HermEsb,代码行数:12,代码来源:InstallSerializers.cs

示例5: GetMemberInformation

        public MemberModel GetMemberInformation(string slackId)
        {
            var responseString = "https://slack.com/api/users.info"
                                .PostUrlEncodedAsync(new
                                                     {
                                                         token = ConfigurationManager.AppSettings["BotKey"],
                                                         user = CleanSlackId(slackId)
                                                     })
                                .ReceiveString().Result;

            var serializer = new JsonSerializer<UserInfoResponse>();
            var memberInfo = serializer.DeserializeFromString(responseString);

            return memberInfo.user;
        }
开发者ID:prinzo,项目名称:Attack-Of-The-Fines-TA15,代码行数:15,代码来源:MemberInfoApi.cs

示例6: GetUserInfo

        public UserInfoResponseModel GetUserInfo(string slackApiToken, string userSlackId)
        {
            var responseString = "https://slack.com/api/users.info"
                .PostUrlEncodedAsync(
                    new
                    {
                        token = slackApiToken,
                        user = userSlackId
                    })
                .ReceiveString()
                .Result;

            var serializer = new JsonSerializer<UserInfoResponseModel>();
            var response = serializer.DeserializeFromString(responseString);
            return response;
        }
开发者ID:amritpurshotam,项目名称:YodaSlackBot,代码行数:16,代码来源:UserApi.cs

示例7: GetChannelInfo

        public ChannelInfoResponseModel GetChannelInfo(string slackApiToken, string channel)
        {
            var responseString = "https://slack.com/api/channels.info"
                .PostUrlEncodedAsync(
                    new
                    {
                        token = slackApiToken,
                        channel
                    })
                .ReceiveString()
                .Result;

            var serializer = new JsonSerializer<ChannelInfoResponseModel>();
            var response = serializer.DeserializeFromString(responseString);
            return response;
        }
开发者ID:amritpurshotam,项目名称:YodaSlackBot,代码行数:16,代码来源:ChannelApi.cs

示例8: ListChannels

        public ChannelListResponseModel ListChannels(string slackApiToken)
        {
            var responseString = "https://slack.com/api/channels.list"
                .PostUrlEncodedAsync(
                    new
                    {
                        token = slackApiToken,
                        exclude_archived = 0
                    })
                .ReceiveString()
                .Result;

            var serializer = new JsonSerializer<ChannelListResponseModel>();
            var response = serializer.DeserializeFromString(responseString);
            return response;
        }
开发者ID:amritpurshotam,项目名称:YodaSlackBot,代码行数:16,代码来源:ChannelApi.cs

示例9: UpdateMessage

        public ChatUpdateResponseModel UpdateMessage(string slackApiToken, double messageTimeStamp, string channel, string text)
        {
            var responseString = "https://slack.com/api/chat.update"
                .PostUrlEncodedAsync(
                    new
                    {
                        token = slackApiToken,
                        ts = messageTimeStamp,
                        channel,
                        text
                    })
                .ReceiveString()
                .Result;

            var serializer = new JsonSerializer<ChatUpdateResponseModel>();
            var response = serializer.DeserializeFromString(responseString);
            return response;
        }
开发者ID:amritpurshotam,项目名称:YodaSlackBot,代码行数:18,代码来源:ChatApi.cs

示例10: PostMessage

        public PostMessageResponseModel PostMessage(string slackApiToken, string channel, string text)
        {
            var responseString = "https://slack.com/api/chat.postMessage"
                .PostUrlEncodedAsync(
                    new
                    {
                        token = slackApiToken,
                        channel,
                        text,
                        as_user = true
                    })
                .ReceiveString()
                .Result;

            var serializer = new JsonSerializer<PostMessageResponseModel>();
            var response = serializer.DeserializeFromString(responseString);
            return response;
        }
开发者ID:amritpurshotam,项目名称:YodaSlackBot,代码行数:18,代码来源:ChatApi.cs

示例11: AddReaction

        public bool AddReaction(string reaction, string channel, string timestamp)
        {
            var responseString = "https://slack.com/api/reactions.add"
                .PostUrlEncodedAsync(
                    new
                    {
                        token = ConfigurationManager.AppSettings["SlackBotApiToken"],
                        name = reaction,
                        channel,
                        timestamp
                    })
                .ReceiveString()
                .Result;

            var serializer = new JsonSerializer<ReactionResponseModel>();
            var response = serializer.DeserializeFromString(responseString);
            return response.ok;
        }
开发者ID:amritpurshotam,项目名称:YodaSlackBot,代码行数:18,代码来源:ReactionApi.cs

示例12: ListGroups

        public GroupsListResponseModel ListGroups(string slackApiToken)
        {
            var responseString = "https://slack.com/api/groups.list"
                .PostUrlEncodedAsync(
                    new
                    {
                        token = slackApiToken,
                        exclude_archived = 0
                    })
                .ReceiveString()
                .Result;

            var serializer = new JsonSerializer<GroupsListResponseModel>();
            var response = serializer.DeserializeFromString(responseString);

            if (!response.ok)
            {
                throw new SlackApiException(response.error);
            }
            return response;
        }
开发者ID:prinzo,项目名称:Attack-Of-The-Fines-TA15,代码行数:21,代码来源:GroupsApi.cs

示例13: TryGetErrorMessage

        public static string TryGetErrorMessage(object param)
        {
            var error = param as Error;
            if (error == null || error.Exception == null || string.IsNullOrEmpty(error.Exception.Message))
                return null;

            string msg = null;
            if (error.Exception.Message.StartsWith("["))
            {
                var serializer = new JsonSerializer<List<ErrorInfo>>();
                try
                {
                    var errorList = serializer.DeserializeFromString(error.Exception.Message);
                    var sb = new StringBuilder();
                    foreach (var errorInfo in errorList)
                    {
                        sb.AppendLine(LanguageHelper.GetValue(errorInfo.Message));
                    }
                    msg = sb.ToString();
                }
                catch
                {

                }
            }
            else
            {
                string errMessage = error.Exception.Message;
                if (errMessage.StartsWith("\""))
                    errMessage = errMessage.Replace("\"", "");

                msg = LanguageHelper.GetValue(errMessage);

            }

             if (string.IsNullOrEmpty(msg))
                    msg = error.Exception.Message;

            return msg;
        }
开发者ID:antonmaju,项目名称:egg-farm-system,代码行数:40,代码来源:LanguageHelper.cs

示例14: Main

        static void Main(string[] args)
        {
            var violations = 0;
            const int count = 1000 * 1000;
            var json = new List<string>();
            var serializer = new JsonSerializer<T>();
            for (int i = 0; i < count; i++)
            {
                var t = new T
                {
                    X = Guid.NewGuid(),
                    Y = i % 2 == 0 ? 'C' : 'P',
                };
                json.Add(serializer.SerializeToString(t));
            }

            var tasks = new List<Task>();
            var tasksCount = args.Length > 0 ? int.Parse(args[0]) : 3;
            for (int jj = 0; jj < tasksCount; jj++)
            {
                int j = jj;
                tasks.Add(Task.Run(() => {
                    for (int i = 0; i < count; i++)
                    {
                        string s = json[i];
                        var t = serializer.DeserializeFromString(s);
                        if (t.Y != (i % 2 == 0 ? 'C' : 'P'))
                        {
                            violations++;
                            Console.WriteLine("Constraint violation index {0} thread {1} expected: {2} received: {3} json: {4}",
                                i, j, i % 2 == 0 ? 'C' : 'P', t.Y, s);
                        }
                    }
                }));
            }
            tasks.ForEach(task => task.Wait());

            Console.WriteLine($"There were {violations} viloations, running {tasksCount} Tasks");
        }
开发者ID:ServiceStack,项目名称:ServiceStack.Text,代码行数:39,代码来源:Program.cs

示例15: GetGroupInfo

        public GroupsInfoResponseModel GetGroupInfo(string slackApiToken, string channel)
        {
            var responseString = "https://slack.com/api/groups.info"
                .PostUrlEncodedAsync(
                    new
                    {
                        token = slackApiToken,
                        channel
                    })
                .ReceiveString()
                .Result;

            var serializer = new JsonSerializer<GroupsInfoResponseModel>();
            var response = serializer.DeserializeFromString(responseString);

            if (!response.ok)
            {
                throw new SlackApiException(response.error);
            }

            return response;
        }
开发者ID:prinzo,项目名称:Attack-Of-The-Fines-TA15,代码行数:22,代码来源:GroupsApi.cs


注:本文中的JsonSerializer.DeserializeFromString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。