本文整理汇总了C#中JsonDeserializer类的典型用法代码示例。如果您正苦于以下问题:C# JsonDeserializer类的具体用法?C# JsonDeserializer怎么用?C# JsonDeserializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonDeserializer类属于命名空间,在下文中一共展示了JsonDeserializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetToken_Click
private void GetToken_Click(object sender, RoutedEventArgs e)
{
var client = new RestClient("https://api.home.nest.com/oauth2/access_token");
var request = new RestRequest(Method.POST);
request.AddParameter("client_id", TextNestClientId.Text);
request.AddParameter("code", TextNestPin.Text);
request.AddParameter("client_secret", PwNestSecret.Password);
request.AddParameter("grant_type", "authorization_code");
var response = client.Execute(request);
JsonDeserializer deserializer = new JsonDeserializer();
var json = deserializer.Deserialize<Dictionary<string, string>>(response);
if (json.ContainsKey("access_token"))
{
TextNestAccessToken.Text = json["access_token"];
return;
}
if (json.ContainsKey("message"))
{
TextNestAccessToken.Text = json["message"];
return;
}
if (json.ContainsKey("error_description"))
{
TextNestAccessToken.Text = json["error_description"];
return;
}
}
示例2: Setup
public void Setup()
{
string url = ConfigurationManager.AppSettings["url"];
string clientKey = ConfigurationManager.AppSettings["client-key"];
string clientSecret = ConfigurationManager.AppSettings["client-secret"];
responsePath = ConfigurationManager.AppSettings["response-path"];
Assert.IsNotNullOrEmpty(clientKey);
Assert.IsNotNullOrEmpty(clientSecret);
Assert.IsNotNullOrEmpty(url);
// ReSharper disable UnusedVariable
//##BEGIN EXAMPLE accessingapi##
var api = new Api(url, clientKey, clientSecret);
var tokenResponse = api.Authenticate();
var rootLinks = api.Root;
//##END EXAMPLE##
// ReSharper restore UnusedVariable
responses = ResponseReader.readResponses(responsePath);
deserializer = new JsonDeserializer();
TestUtils.Deserializer = deserializer;
}
示例3: HitboxOnlineState
private static bool HitboxOnlineState(string sStream)
{
var req = new RestRequest("/media/live/" + sStream, Method.GET);
IRestClientProvider _restClientProvider = new RestClientProvider(new RestClient("http://api.hitbox.tv"));
var response = _restClientProvider.Execute(req);
try
{
var des = new JsonDeserializer();
var data = des.Deserialize<HitboxRootObject>(response);
foreach (var item in data.livestream)
{
if(item.media_user_name.ToLower() == sStream.ToLower())
{
if(item.media_is_live == "1")
{
return true;
}
}
}
return false;
}
catch (Exception)
{
return false;
}
}
示例4: OnContentReceived
private void OnContentReceived(string content) {
JsonDeserializer deserializer = new JsonDeserializer();
var response = new RestResponse();
response.Content = content;
MessageContent messageContent = null;
try {
messageContent = deserializer.Deserialize<MessageContent>(response);
} catch {
MessageContent = null;
}
if (messageContent != null) {
MessageContent = messageContent;
if (Event == "message" || Event == "comment") {
ExtractedBody = messageContent.Text;
}
} else if(Event == "message") {
ExtractedBody = content;
}
Displayable = ExtractedBody != null;
TimeStamp = UnixTimeToLocal(Sent);
}
示例5: TestReadTrelloExport
public void TestReadTrelloExport()
{
var contents = File.ReadAllText("..\\..\\..\\..\\Data\\Trello\\testExport.json");
var x = new JsonDeserializer();
var dato = SimpleJson.DeserializeObject<Board>(contents);
}
示例6: JSONDeserializationTest
public void JSONDeserializationTest() {
var path = Path.Combine(Environment.CurrentDirectory, "User.json");
var ds = new JsonDeserializer();
var response = new RestResponse() { ContentType = "application/json", ResponseStatus = ResponseStatus.Completed, StatusCode = System.Net.HttpStatusCode.OK };
// Read the file as one string.
StreamReader myFile = new StreamReader(path);
string json = myFile.ReadToEnd();
myFile.Close();
response.Content = json;
var myUser = ds.Deserialize<User>(response);
Assert.IsNotNull(myUser);
Assert.AreEqual("PT23IWX", myUser.id);
Assert.AreEqual("Tim Wright", myUser.name);
Assert.AreEqual("[email protected]", myUser.email);
Assert.AreEqual("Eastern Time (US & Canada)", myUser.time_zone);
Assert.AreEqual("purple", myUser.color);
Assert.AreEqual("owner", myUser.role);
Assert.AreEqual("https://secure.gravatar.com/avatar/923a2b907dc04244e9bb5576a42e70a7.png?d=mm&r=PG", myUser.avatar_url);
Assert.AreEqual("/users/PT23IWX", myUser.user_url);
Assert.AreEqual(false, myUser.invitation_sent);
Assert.AreEqual(false, myUser.marketing_opt_out);
}
示例7: ReplayAllEvents
public void ReplayAllEvents()
{
using (IDocumentSession session = _eventStorage.OpenSession())
{
int startPos = 0;
while (true)
{
RavenQueryStatistics stats;
var events = session.Query<EventDescriptor>()
.Statistics(out stats)
.OrderBy(ev => ev.AggregateId)
.ThenBy(ev => ev.Version)
.Select(ev => ev)
.Skip(startPos)
.ToArray();
JsonDeserializer deserializer = new JsonDeserializer();
foreach (EventDescriptor ev in events)
{
Publish(deserializer.Deserialize(ev.EventType, ev.EventData));
}
if (stats.TotalResults <= startPos)
{
break;
}
startPos += 128;
}
}
}
示例8: JiraRestClient
public JiraRestClient(string baseUrl, string username, string password)
{
this.username = username;
this.password = password;
deserializer = new JsonDeserializer();
client = new RestClient { BaseUrl = new Uri(baseUrl + (baseUrl.EndsWith("/") ? "" : "/") + "rest/api/2/") };
}
示例9: JSONDeserializationTest
public void JSONDeserializationTest() {
var path = Path.Combine(Environment.CurrentDirectory, "Schedule.json");
var ds = new JsonDeserializer();
var response = new RestResponse() { ContentType = "application/json", ResponseStatus = ResponseStatus.Completed, StatusCode = System.Net.HttpStatusCode.OK };
// Read the file as one string.
StreamReader myFile = new StreamReader(path);
string json = myFile.ReadToEnd();
myFile.Close();
response.Content = json;
var mySchedule = ds.Deserialize<Schedule>(response);
Assert.IsNotNull(mySchedule);
Assert.IsNotNull(mySchedule.escalation_policies);
Assert.AreEqual("FS4LEQD", mySchedule.id);
Assert.AreEqual("24x7 Schedule", mySchedule.name);
Assert.AreEqual("UTC", mySchedule.time_zone);
Assert.AreEqual(new DateTime(635726880000000000), mySchedule.today);
Assert.AreEqual(1, mySchedule.escalation_policies.Count);
Assert.AreEqual("PAD5HK6", mySchedule.escalation_policies[0].id);
Assert.AreEqual("Escalation Policy - 24x7", mySchedule.escalation_policies[0].name);
}
示例10: JSONDeserializationTest
public void JSONDeserializationTest() {
var path = Path.Combine(Environment.CurrentDirectory, "Incident.json");
var ds = new JsonDeserializer();
var response = new RestResponse() { ContentType = "application/json", ResponseStatus = ResponseStatus.Completed, StatusCode = System.Net.HttpStatusCode.OK };
// Read the file as one string.
StreamReader myFile = new StreamReader(path);
string json = myFile.ReadToEnd();
myFile.Close();
response.Content = json;
var myAlert = ds.Deserialize<Incident>(response);
Assert.IsNotNull(myAlert);
Assert.IsNotNull(myAlert.service);
Assert.IsNotNull(myAlert.last_status_change_by);
Assert.AreEqual("1", myAlert.incident_number);
Assert.AreEqual(new DateTime(634830005610000000), myAlert.created_on);
Assert.AreEqual("resolved", myAlert.status);
Assert.AreEqual("https://acme.pagerduty.com/incidents/P2A6J96", myAlert.html_url);
Assert.AreEqual(null, myAlert.incident_key);
Assert.AreEqual(null, myAlert.assigned_to_user);
Assert.AreEqual("https://acme.pagerduty.com/incidents/P2A6J96/log_entries/P2NQP6P", myAlert.trigger_details_html_url);
Assert.AreEqual(new DateTime(634830006590000000), myAlert.last_status_change_on);
}
示例11: FetchDiff
public bool FetchDiff (Push push)
{
string url = null;
try {
string response = CachingFetcher.FetchDiff (push.CHAuthID, push.Repository.Owner.Name, push.Repository.Name, ID, out url);
if (response == null)
return false;
var jdes = new JsonDeserializer ();
var wrapper = jdes.Deserialize<CommitWithDiffJsonWrapper> (response);
if (wrapper != null) {
var diff = wrapper.Commit;
if (!diff.FetchBlobs (push)) {
Log (LogSeverity.Error, "Failed to fetch blobs for commit '{0}' from URL '{1}'", ID, url);
return false;
}
Diff = diff;
} else {
Log (LogSeverity.Error, "Failed to fetch diff for commit '{0}' from URL '{1}'", ID, url);
return false;
}
} catch (Exception ex) {
Log (ex, "Exception while fetching diff for commit '{4}' from URL '{5}'\n{0}", ID, url);
return false;
}
CommitWithDiff ret = Diff;
if (ret == null)
Log (LogSeverity.Info, "FetchDiff did not fail, but no diff retrieved?");
return ret != null;
}
示例12: TestDeserializeChannelResult
public void TestDeserializeChannelResult()
{
var doc = File.ReadAllText(Path.Combine("Resources", "channels.json"));
var json = new JsonDeserializer();
var output = json.Deserialize<ChannelResult>(new RestResponse {Content = doc});
Assert.NotNull(output);
Assert.NotNull(output.Channels);
Assert.AreEqual(1, output.Channels.Count);
Assert.AreEqual("CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", output.Channels[0].Sid);
Assert.AreEqual("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", output.Channels[0].AccountSid);
Assert.AreEqual("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", output.Channels[0].ServiceSid);
Assert.AreEqual("my channel", output.Channels[0].FriendlyName);
Assert.IsEmpty(output.Channels[0].Attributes);
Assert.AreEqual("system", output.Channels[0].CreatedBy);
Assert.AreEqual("public", output.Channels[0].Type);
Assert.AreEqual(
"http://localhost/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
output.Channels[0].Url);
Dictionary<string, string> dictionary = output.Channels[0].Links;
Assert.NotNull(dictionary);
Assert.True(dictionary.ContainsKey("members"));
Assert.True(dictionary.ContainsKey("messages"));
Assert.AreEqual(
"http://localhost/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Members",
dictionary["members"]);
Assert.AreEqual(
"http://localhost/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages",
dictionary["messages"]);
}
示例13: GetParams
public static SinusModel GetParams()
{
var request = new RestRequest(Method.GET);
request.Resource = "model/" + ModelId;
IRestResponse response = client.Execute (request);
var json = new JsonDeserializer();
return json.Deserialize<SinusModel>(response);
}
示例14: AccessTokenClient
/// <summary>
/// Initializes a new instance of the <see cref="AccessTokenClient"/> class.
/// </summary>
/// <param name="serverConfiguration">The client configuration.</param>
/// <exception cref="System.ArgumentNullException">clientConfiguration</exception>
public AccessTokenClient(OAuthServerConfiguration serverConfiguration)
{
Requires.NotNull(serverConfiguration, "clientConfiguration");
this.jsonDeserializer = new JsonDeserializer();
this.serverConfiguration = serverConfiguration;
this.RestClient = new RestClient(serverConfiguration.BaseUrl.ToString());
}
示例15: Deserialize_SerializationRepresentation_DeserializedObject
public void Deserialize_SerializationRepresentation_DeserializedObject()
{
var subject = new JsonDeserializer();
var deserialized = subject.Deserialize<Serializable>(Serializable.JsonString("s", 3m));
Assert.That(deserialized.D, Is.EqualTo(3m));
Assert.That(deserialized.S, Is.EqualTo("s"));
}