ConvertJsonToList

This commit is contained in:
2014-05-03 18:54:19 +02:00
parent 07c9f06f75
commit a207ca7ca4
3 changed files with 35 additions and 2 deletions
+12
View File
@@ -121,6 +121,18 @@ namespace PocketSharp
}
/// <summary>
/// Converts a raw JSON response to a PocketItem list
/// </summary>
/// <param name="itemsJSON">The raw JSON response.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
public IEnumerable<PocketItem> ConvertJsonToList(string itemsJSON)
{
return DeserializeJson<Retrieve>(itemsJSON).Items;
}
/// <summary>
/// Retrieves all available tags.
/// Note: The Pocket API contains no method, which allows to retrieve all tags, so all items are retrieved and the associated tags extracted.
+8
View File
@@ -160,6 +160,14 @@ namespace PocketSharp
/// <exception cref="PocketException"></exception>
Task<IEnumerable<PocketItem>> Get(RetrieveFilter filter, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Converts a raw JSON response to a PocketItem list
/// </summary>
/// <param name="itemsJSON">The raw JSON response.</param>
/// <returns></returns>
/// <exception cref="PocketException"></exception>
IEnumerable<PocketItem> ConvertJsonToList(string itemsJSON);
/// <summary>
/// Retrieves all available tags.
/// Note: The Pocket API contains no method, which allows to retrieve all tags, so all items are retrieved and the associated tags extracted.
+15 -2
View File
@@ -215,11 +215,24 @@ namespace PocketSharp
// cache response
lastResponseData = responseString;
responseString = responseString.Replace("[]", "{}");
return DeserializeJson<T>(responseString);
}
/// <summary>
/// Converts JSON to Pocket objects
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="json">Raw JSON response</param>
/// <returns></returns>
/// <exception cref="PocketException">Parse error.</exception>
protected T DeserializeJson<T>(string json) where T : class, new()
{
json = json.Replace("[]", "{}");
// deserialize object
T parsedResponse = JsonConvert.DeserializeObject<T>(
responseString,
json,
new JsonSerializerSettings
{
Error = (object sender, ErrorEventArgs args) =>