0

I'm trying to deserialize a JSON,

So My request return a JSON like this :

{
    "total_records": 5547,
    "total_searched": 4284178,
    "articles": [{
        "rank": 1,
        "content_type": "Conference",
        "article_number": "6482896",
        "doi": "10.1109/EDSSC.2012.6482896",
        "title": "Development of low stress TaN thin film for MEMS/sensor electrode application",
        "publication_number": 6475438,
        "publication_title": "2012 IEEE International Conference on Electron Devices and Solid State Circuit (EDSSC)",
        "isbn": "New-2005_Electronic_978-1-4673-5696-1",
        "publisher": "IEEE",
        "citing_paper_count": 0,
        "index_terms": {
            "ieee_terms": {
                "terms": ["Conductivity", "Electrodes", "Films", "Metals", "Resistance", "Silicon", "Stress"]
            },
            "author_terms": {
                "terms": ["MEMs", "PVD", "TaN", "stress"]
            }
        },
        "pdf_url": "http://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=6482896",
        "abstract_url": "http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=6482896",
        "html_url": "http://ieeexplore.ieee.org/xpls/icp.jsp?arnumber=6482896",
        "authors": {
            "authors": [{
                "full_name": "Xiaoxu Kang",
                "author_order": 1
            }, {
                "full_name": "Qingyun Zuo",
                "author_order": 2
            }, {
                "full_name": "Chao Yuan",
                "author_order": 3
            }, {
                "full_name": "Shoumian Chen",
                "author_order": 4
            }, {
                "full_name": "Yuhang Zhao",
                "author_order": 5
            }]
        },
        "conference_location": "Bangkok",
        "conference_dates": "3-5 Dec. 2012",
        "start_page": "1",
        "end_page": "3", ...

But I want only the "authors" part. So I tried to deserialize it, therefore I generated all the classes thanks to json2csharp.

    public class IeeeTerms
    {
        public List<string> terms { get; set; }
    }


    public class AuthorTerms
    {
        public List<string> terms { get; set; }
    }


    public class IndexTerms
    {
        public IeeeTerms ieee_terms { get; set; }
        public AuthorTerms author_terms { get; set; }
    }

    public class Author
    {
        public string full_name { get; set; }
        public int author_order { get; set; }
    }

    public class Authors
    {
        public List<Author> authors { get; set; }
    }

    public class Article
    {
        public int rank { get; set; }
        public string content_type { get; set; }
        public string article_number { get; set; }
        public string doi { get; set; }
        public string title { get; set; }
        public int publication_number { get; set; }
        public string publication_title { get; set; }
        public string isbn { get; set; }
        public string publisher { get; set; }
        public int citing_paper_count { get; set; }
        public IndexTerms index_terms { get; set; }
        public string pdf_url { get; set; }
        public string abstract_url { get; set; }
        public string html_url { get; set; }
        public Authors authors { get; set; }
        public string conference_location { get; set; }
        public string conference_dates { get; set; }
        public string start_page { get; set; }
        public string end_page { get; set; }
        public string @abstract { get; set; }
        public string issue { get; set; }
        public int? is_number { get; set; }
        public string volume { get; set; }
        public string issn { get; set; }
        public string publication_date { get; set; }
    }

    public class RootObject
    {
        public int total_records { get; set; }
        public int total_searched { get; set; }
        public List<Article> articles { get; set; }
    }

Then I try to parse the reponse.Content of my request which correspond to the JSON above.

var client = new RestClient("http://ieeexploreapi.ieee.org/api/v1/search/articles?");
            var request = new RestRequest("articles", Method.GET);
            request.AddParameter("article_number", "6482896");
            request.AddParameter("format", "Json");
            request.AddParameter("max_records", "10");
            request.AddParameter("apikey", "somekey");
            var response = client.Execute(request);
            RestSharp.Deserializers.JsonDeserializer deserial = new JsonDeserializer();

            return new JsonResult()
            {
                Data = deserial.Deserialize<Article>(response);,
            };


            }

But when I execute my code I have the following error : The type 'IEEEAPI.Controllers.MinerController+Article' with the name of the Data contract 'MinerController.Article:http://schemas.datacontract.org/2004/07/IEEEAPI.Controllers' is not expected.

Can someone explain me the problem ?

Squogo
  • 21
  • 2
  • use like this - Data = deserial.Deserialize(response);, – Power Star Aug 21 '17 at 12:12
  • You can't just mix and match the parts you want to deserialize. Well, you can, but you don't want to. Deserialize the whole thing from the root and access `result.articles[0].authors`. See also the duplicate for explanation. – CodeCaster Aug 21 '17 at 12:12

0 Answers0