ConvertJsonToList
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) =>
|
||||
|
||||
Reference in New Issue
Block a user