本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
示例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;
}