diff --git a/PocketSharp/Components/Get.cs b/PocketSharp/Components/Get.cs index fa5a46d..70e40ec 100644 --- a/PocketSharp/Components/Get.cs +++ b/PocketSharp/Components/Get.cs @@ -121,6 +121,18 @@ namespace PocketSharp } + /// + /// Converts a raw JSON response to a PocketItem list + /// + /// The raw JSON response. + /// + /// + public IEnumerable ConvertJsonToList(string itemsJSON) + { + return DeserializeJson(itemsJSON).Items; + } + + /// /// 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. diff --git a/PocketSharp/IPocketClient.cs b/PocketSharp/IPocketClient.cs index d7a7308..caefcab 100644 --- a/PocketSharp/IPocketClient.cs +++ b/PocketSharp/IPocketClient.cs @@ -160,6 +160,14 @@ namespace PocketSharp /// Task> Get(RetrieveFilter filter, CancellationToken cancellationToken = default(CancellationToken)); + /// + /// Converts a raw JSON response to a PocketItem list + /// + /// The raw JSON response. + /// + /// + IEnumerable ConvertJsonToList(string itemsJSON); + /// /// 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. diff --git a/PocketSharp/PocketClient.cs b/PocketSharp/PocketClient.cs index cd422f7..5e9bcb5 100644 --- a/PocketSharp/PocketClient.cs +++ b/PocketSharp/PocketClient.cs @@ -215,11 +215,24 @@ namespace PocketSharp // cache response lastResponseData = responseString; - responseString = responseString.Replace("[]", "{}"); + return DeserializeJson(responseString); + } + + + /// + /// Converts JSON to Pocket objects + /// + /// + /// Raw JSON response + /// + /// Parse error. + protected T DeserializeJson(string json) where T : class, new() + { + json = json.Replace("[]", "{}"); // deserialize object T parsedResponse = JsonConvert.DeserializeObject( - responseString, + json, new JsonSerializerSettings { Error = (object sender, ErrorEventArgs args) =>