From: GSonofNun Date: Tue, 16 Sep 2014 19:37:30 +0000 (-0400) Subject: Updated JSON deserialization method X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=30d0000ca3f06c33dbf6c71c4ad5d9743b31118d;p=inbox.net.git Updated JSON deserialization method --- diff --git a/inbox_net/InboxClient.cs b/inbox_net/InboxClient.cs index 9c6cfc6..585ca1e 100644 --- a/inbox_net/InboxClient.cs +++ b/inbox_net/InboxClient.cs @@ -52,7 +52,7 @@ namespace inbox_net List namespaces = new List(); if (json != null) { - namespaces = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject>(json)); + namespaces = await DeserializeObjectAsync>(json); } return namespaces.First(); } @@ -63,7 +63,7 @@ namespace inbox_net Namespace ns = null; if (json != null) { - ns = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject(json)); + ns = await DeserializeObjectAsync(json); } return ns; } @@ -80,7 +80,7 @@ namespace inbox_net IEnumerable tags = null; if (json != null) { - tags = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject>(json)); + tags = await DeserializeObjectAsync>(json); } return tags; } @@ -91,7 +91,7 @@ namespace inbox_net Tag tag = null; if (json != null) { - tag = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject(json)); + tag = await DeserializeObjectAsync(json); } return tag; } @@ -104,7 +104,7 @@ namespace inbox_net Tag tag = null; if (json != null) { - tag = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject(json)); + tag = await DeserializeObjectAsync(json); } return tag; } @@ -117,7 +117,7 @@ namespace inbox_net Tag tag = null; if (json != null) { - tag = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject(json)); + tag = await DeserializeObjectAsync(json); } return tag; } @@ -133,7 +133,7 @@ namespace inbox_net Thread thread = null; if (json != null) { - thread = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject(json)); + thread = await DeserializeObjectAsync(json)); } return thread; } @@ -147,17 +147,22 @@ namespace inbox_net IEnumerable threads = null; if (json != null) { - threads = await Task.Factory.StartNew(() => JsonConvert.DeserializeObject>(json)); + threads = await DeserializeObjectAsync>(json); } return threads; } - public async Task UpdateThreadTags(string thread_id, string[] add_tags) + public async Task UpdateThreadTags(string thread_id, string[] add_tags) { List> parameters = new List>(); parameters.Add(new KeyValuePair("add_tags", StringsToJsonArray(add_tags))); string json = await HttpPut(GenerateUri(string.Format(MethodURIs.Thread, this.Namespace, thread_id)), GenerateRequestBody(parameters)); - + Thread thread = null; + if (json != null) + { + thread = await DeserializeObjectAsync(json); + } + return thread; } @@ -343,5 +348,10 @@ namespace inbox_net return sb.ToString(); } + private async Task DeserializeObjectAsync(string json) + { + return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject(json)); + } + } }