E
E
estry2019-07-24 11:32:52
JSON
estry, 2019-07-24 11:32:52

How to parse non-constant data type from JSON string?

Hello. I'm parsing JSON. Everything would be great, if not for one but!
At the first request, the id field is given in string, in the second request it is already an object. Because of this, parsing is constantly crumbling.
I first make classes for parsing, then I declare a new class object and deserialize the data.
How to make it possible to parse both string and object data type?
For example, from the first to the last page goes

public class Pagination
{
    public string resultCountMessage { get; set; }
    public int currentPageSize { get; set; }
    public int totalResults { get; set; }
    public object firstPageUrl { get; set; }
    public string nextPageUrl { get; set; }
    public object prevPageUrl { get; set; }
    public string lastPageUrl { get; set; }
    public List<PageButtonUrl> pageButtonUrls { get; set; }
}

And on the last one like this
public class Pagination
{
    public string resultCountMessage { get; set; }
    public int currentPageSize { get; set; }
    public int totalResults { get; set; }
    public string firstPageUrl { get; set; }
    public object nextPageUrl { get; set; }
    public string prevPageUrl { get; set; }
    public object lastPageUrl { get; set; }
    public List<PageButtonUrl> pageButtonUrls { get; set; }
}

{
    "resultCountMessage":"Markoff",
    "currentPageSize":5,
    "totalResults":10,
    "firstPageUrl":"urlfirstpage",
    "nextPageUrl":"urlnextpage",
    "prevPageUrl":"urlprevpage",
    "lastPageUrl":"urllastpage",
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question