How to use MVC to Deserialize Json txt file and return a view

Hello Experts.

I have a task to deserialize a large block of Json in a text file, place it in a class, and output the results to the client browser.  I'm new to Json and MVC but experienced in .Net Webforms, C#.  The results must be in MVC.  Below is my attempt at coding it.  Your help is greatly appreciated.

I get this error >>> "The model item passed into the dictionary is of type 'Demo.Models.NrdHealthMember', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Demo.Models.NrdHealthMember]'. "


TXT File

{"total_resources":926,"page_size":500,"total_pages":2,"current_offset":0,"next_offset":500,"previous_offset":0,"resources":[{"title":"American Veterans with Brain Injuries (AVBI)","newItem":false,"linkName":"http://www.avbi.org/","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104750","phoneNumber":"","governmentSupportedSite":false,"content":"Offers personal stories, resources and announcements of services available to Veterans with traumatic brain injury and their families. ","startDate":"2008-09-16T05:00:00Z","endDate":"2020-03-15T05:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider","Veteran"],"geographicServiceLocations":[],"subjects":["Family & Caregiver Support","Health"]},{"title":"Answers for Veteran or Active Military with Paralysis or Brain Injury","newItem":false,"linkName":"http://www.christopherreeve.org/atf/cf/%7B219882e9-dfff-4cc0-95ee-3a62423c40ec%7D/VET%20BROCHURE%20624_LAYOUT%201.PDF","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104751","phoneNumber":"","governmentSupportedSite":false,"content":"<p>Learn about resources available from the Christopher and Dana Reeve Foundation Paralysis Resource Center, the Defense and Veterans Brain Injury Center and the Brain Injury Association of America to enhance the care of people with paralysis and traumatic brain injury.<\/p>","startDate":"2008-10-20T05:00:00Z","endDate":"2020-04-18T05:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"Army Behavioral Health","newItem":false,"linkName":"http://www.behavioralhealth.army.mil/","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104752","phoneNumber":"","governmentSupportedSite":true,"content":"<p>Learn about post-traumatic stress disorder (PTSD), <a href=\"http://www.behavioralhealth.army.mil/tools/faqschainteaching.html\">traumatic brain injury (TBI)<\/a> and suicide prevention. Includes help for <a href=\"http://www.behavioralhealth.army.mil/families/index.html\" target=\"_blank\">children, couples and extended families<\/a>.<\/p>","startDate":"2008-05-25T05:00:00Z","endDate":"2015-11-21T06:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider"],"geographicServiceLocations":[],"subjects":["Family & Caregiver Support","Health"]},{"title":"Basic Facts about TBI Video","newItem":false,"linkName":"http://www.brainandspinalcord.org/media-center/FactsAboutTBI.html","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104753","phoneNumber":"","governmentSupportedSite":false,"content":"<p>Watch a video from the <a href=\"http://www.brainandspinalcord.org\" target=\"_blank\">Brain and Spinal Cord Injury Center<\/a> provides a basic overview of TBI.<\/p>","startDate":"2009-01-09T06:00:00Z","endDate":"2020-07-08T05:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"Betty Clooney Foundation for Persons with Traumatic Brain Injury (TBI)","newItem":false,"linkName":"http://www.bcftbi.org/","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104754","phoneNumber":"","governmentSupportedSite":false,"content":"<p>Provides resources in finding the right treatment, therapy and rehabilitation for patients with TBI. Includes information on <a href=\"http://www.bcftbi.org/aboutSoldiers.asp\" target=\"_blank\">Soldiers &amp; TBI<\/a>, <a href=\"http://www.bcftbi.org/services.html\" target=\"_blank\">services available<\/a> at their facility in Southern California and a listing of <a href=\"http://www.bcftbi.org/supportGroups.asp\" target=\"_blank\">Support Groups<\/a> in California.<\/p>","startDate":"2008-11-13T06:00:00Z","endDate":"2020-05-12T05:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"Blast Injury FAQs","newItem":false,"linkName":"http://www.dvbic.org/blast-injuries","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104755","phoneNumber":"","governmentSupportedSite":true,"content":"<p>Offers answers to frequently asked questions about blast injuries provided by the <a href=\"http://www.dvbic.org\" target=\"_blank\">Defense &amp; Veterans Brain Injury Center (DVBIC)<\/a>.<\/p>","startDate":"2008-09-15T05:00:00Z","endDate":"2020-03-14T05:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"Bob Woodruff Foundation","newItem":false,"linkName":"http://remind.org/","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104756","phoneNumber":"","governmentSupportedSite":false,"content":"<p>Provides resources and support to injured Service Members, Veterans and their families, especially those who have sustained the hidden injuries of war.<\/p>","startDate":"2008-08-22T05:00:00Z","endDate":"2020-02-18T06:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"Brain Injury Network","newItem":false,"linkName":"http://www.braininjurynetwork.org/","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104757","phoneNumber":"","governmentSupportedSite":false,"content":"<p>Provides advocacy, peer support, and resources for survivors of acquired brain injury (ABI), which includes traumatic brain injury (TBI), stroke, brain illness and brain tumors.<\/p>","startDate":"2008-11-20T06:00:00Z","endDate":"2020-05-19T05:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"BrainLine","newItem":false,"linkName":"http://www.brainline.org/index.php","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104758","phoneNumber":"","governmentSupportedSite":false,"content":"<p>Provides a variety of information and resources on traumatic brain injury (TBI).<\/p>","startDate":"2008-08-07T05:00:00Z","endDate":"2020-02-03T06:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"Defense Centers of Excellence (DCoE)","newItem":false,"linkName":"http://www.dcoe.health.mil/","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104759","phoneNumber":"","governmentSupportedSite":true,"content":"<p>Access a DoD program that works to improve psychological health and TBI treatment of Service Members and Veterans. <\/p>\n","startDate":"2008-06-17T05:00:00Z","endDate":"2020-12-14T06:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"Employment after Traumatic Brain Injury (TBI)","newItem":false,"linkName":"http://biausa.fyrian.com/_literature_43314/employment_after_brain_injury","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104760","phoneNumber":"","governmentSupportedSite":false,"content":"<p>Learn about research and expectations regarding post-TBI vocational outcomes. Lists frequently asked questions and factsheets on employment options and useful information when living with a TBI.<\/p>","startDate":"2008-05-11T05:00:00Z","endDate":"2020-11-07T06:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"Facts About Traumatic Brain Injury (TBI)","newItem":false,"linkName":"http://www.biausa.org/","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104761","phoneNumber":"","governmentSupportedSite":false,"content":"<p>Learn about TBI from the <a href=\"http://www.biausa.org\" target=\"_blank\">Brain Injury Association of America (BIAA)<\/a>. BIAA also offers an <a href=\"https://secure.biausa.org/OnlineDirectory/Directory/SearchType4.aspx\" target=\"_blank\">online directory<\/a> of brain injury rehabilitation programs and services across the US.<\/p>","startDate":"2008-09-14T05:00:00Z","endDate":"2020-03-13T05:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"Healthcare for Headaches","newItem":false,"linkName":"http://www.headaches.org/","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104763","phoneNumber":"","governmentSupportedSite":false,"content":"<p>Provides educational and informational resources supporting headache research and treatment. The website provide articles that link headaches to TBI and PTSD.<\/p>","startDate":"2009-03-30T05:00:00Z","endDate":"2020-09-26T05:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"Project Victory","newItem":false,"linkName":"http://www.projectvictory.org/","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104764","phoneNumber":"","governmentSupportedSite":false,"content":"<p>Helps Service Members who have sustained a mild to severe brain injury to regain skills and functions. <\/p>\n","startDate":"2009-02-18T06:00:00Z","endDate":"2020-08-17T05:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"Improved Treatment for Stuttering","newItem":false,"linkName":"http://www.stutteringhelp.org/Default.aspx?tabid=4","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104765","phoneNumber":"","governmentSupportedSite":false,"content":"<p>Provides free online resources, services and support to those who stutter and their families, as well as support for research into the causes of stuttering.<\/p>","startDate":"2009-03-30T05:00:00Z","endDate":"2020-09-26T05:00:00Z","interestGroups":["Service Member","Service Provider","Family Member/Caregiver","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"Mild Traumatic Brain Injury (MTBI) Screening","newItem":false,"linkName":"http://www.dvbic.org/research/mild-traumatic-brain-injury-screening-diagnosis-and-treatment","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104766","phoneNumber":"","governmentSupportedSite":true,"content":"<p>Access tool to identify Service Members who may need further evaluation for MTBI.<\/p>","startDate":"2008-05-25T05:00:00Z","endDate":"2015-11-21T06:00:00Z","interestGroups":["Family Member/Caregiver","Service Member","Service Provider","Veteran"],"geographicServiceLocations":[],"subjects":["Health"]},{"title":"National Council on Disability - Report on the Invisible Wounds of TBI & PTSD","newItem":false,"linkName":"http://www.ncd.gov/newsroom/publications/","linkUrl":"https://www.nrd.gov/clickTrack/confirm/14104767","phoneNumber":"","governmentSupportedSite":true,"content":"<p>Describes the less visible psychological and neurological injuries associated with post traumatic stress disorder (PTSD) or traumatic brain injury (TBI). Download a report titled <a href=\"http://www.ncd.gov/publications/2009/March042009\" target=\"_blank\">Invisible Wounds: Serving Service Members and Veterans with PTSD and TBI<\/a>.<\/p>","startDate":"2009-03-04T06:00:00Z","endDate":"2020-08-31T05:00:00Z"}...

Open in new window




MODELS FOLDER

public class NrdHealthMember
    {
        public string ServiceMember { get; set; }
        public string ServiceProvider { get; set; }
        public string Veterans { get; set; }
        public string State { get; set; }
        public string County { get; set; }
        public int Phone { get; set; }
        public string Address { get; set; }
        public string Health { get; set; }

    }

Open in new window



CONTROLLERS

public class NrdHealthController : Controller
    {

       StreamReader file = System.IO.File.OpenText(@"C:\Documents and Settings\User\My Documents\json-nrd-topic-health.txt");
JsonSerializer serializer = new JsonSerializer();
            NrdHealthMember _nrdHealthMember = (NrdHealthMember)serializer.Deserialize(file, typeof(NrdHealthMember));

 return View(_nrdHealthMember);
           
        }

Open in new window


Global ASAX

routes.MapRoute(
                "NrdHealth",
                "nrdhealth",
                new { controller = "NrdHealth", action = "NrdHealthDisplay" }

                );

Open in new window





I added a view from within the ActionResult, selected strongly typed, and scaffold = List.

Your help is greatly appreciated.
iNetBlazerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
You selected "List" from the scaffold options, so the question would be, "Is the JSON string a list of objects?"

You are deserializing it as a single object here:

 NrdHealthMember _nrdHealthMember = (NrdHealthMember)serializer.Deserialize(file, typeof(NrdHealthMember));

Open in new window

0
iNetBlazerAuthor Commented:
Thanks TheLearnedOne, what do you suggest?
0
Bob LearnedCommented:
It is difficult to suggest anything without understanding your question better.  You didn't answer my question.

Is the JSON string a list of objects, or a single object?
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

iNetBlazerAuthor Commented:
The Json is a string of numbers and letters in a file.  I need to programmatically open/read the file, deserialize it, and map it to an object.  Then return a view of the object values.
0
Bob LearnedCommented:
The formatted file contents show this:

{
  "total_resources": 926,
  "page_size": 500,
  "total_pages": 2,
  "current_offset": 0,
  "next_offset": 500,
  "previous_offset": 0,
  "resources": [
    {
      "title": "American Veterans with Brain Injuries (AVBI)",
      "newItem": false,
      "linkName": "http://www.avbi.org/",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104750",
      "phoneNumber": "",
      "governmentSupportedSite": false,
      "content": "Offers personal stories, resources and announcements of services available to Veterans with traumatic brain injury and their families. ",
      "startDate": "2008-09-16T05:00:00Z",
      "endDate": "2020-03-15T05:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Family & Caregiver Support",
        "Health"
      ]
    },
    {
      "title": "Answers for Veteran or Active Military with Paralysis or Brain Injury",
      "newItem": false,
      "linkName": "http://www.christopherreeve.org/atf/cf/%7B219882e9-dfff-4cc0-95ee-3a62423c40ec%7D/VET%20BROCHURE%20624_LAYOUT%201.PDF",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104751",
      "phoneNumber": "",
      "governmentSupportedSite": false,
      "content": "<p>Learn about resources available from the Christopher and Dana Reeve Foundation Paralysis Resource Center, the Defense and Veterans Brain Injury Center and the Brain Injury Association of America to enhance the care of people with paralysis and traumatic brain injury.<\/p>",
      "startDate": "2008-10-20T05:00:00Z",
      "endDate": "2020-04-18T05:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "Army Behavioral Health",
      "newItem": false,
      "linkName": "http://www.behavioralhealth.army.mil/",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104752",
      "phoneNumber": "",
      "governmentSupportedSite": true,
      "content": "<p>Learn about post-traumatic stress disorder (PTSD), <a href=\"http://www.behavioralhealth.army.mil/tools/faqschainteaching.html\">traumatic brain injury (TBI)<\/a> and suicide prevention. Includes help for <a href=\"http://www.behavioralhealth.army.mil/families/index.html\" target=\"_blank\">children, couples and extended families<\/a>.<\/p>",
      "startDate": "2008-05-25T05:00:00Z",
      "endDate": "2015-11-21T06:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Family & Caregiver Support",
        "Health"
      ]
    },
    {
      "title": "Basic Facts about TBI Video",
      "newItem": false,
      "linkName": "http://www.brainandspinalcord.org/media-center/FactsAboutTBI.html",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104753",
      "phoneNumber": "",
      "governmentSupportedSite": false,
      "content": "<p>Watch a video from the <a href=\"http://www.brainandspinalcord.org\" target=\"_blank\">Brain and Spinal Cord Injury Center<\/a> provides a basic overview of TBI.<\/p>",
      "startDate": "2009-01-09T06:00:00Z",
      "endDate": "2020-07-08T05:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "Betty Clooney Foundation for Persons with Traumatic Brain Injury (TBI)",
      "newItem": false,
      "linkName": "http://www.bcftbi.org/",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104754",
      "phoneNumber": "",
      "governmentSupportedSite": false,
      "content": "<p>Provides resources in finding the right treatment, therapy and rehabilitation for patients with TBI. Includes information on <a href=\"http://www.bcftbi.org/aboutSoldiers.asp\" target=\"_blank\">Soldiers &amp; TBI<\/a>, <a href=\"http://www.bcftbi.org/services.html\" target=\"_blank\">services available<\/a> at their facility in Southern California and a listing of <a href=\"http://www.bcftbi.org/supportGroups.asp\" target=\"_blank\">Support Groups<\/a> in California.<\/p>",
      "startDate": "2008-11-13T06:00:00Z",
      "endDate": "2020-05-12T05:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "Blast Injury FAQs",
      "newItem": false,
      "linkName": "http://www.dvbic.org/blast-injuries",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104755",
      "phoneNumber": "",
      "governmentSupportedSite": true,
      "content": "<p>Offers answers to frequently asked questions about blast injuries provided by the <a href=\"http://www.dvbic.org\" target=\"_blank\">Defense &amp; Veterans Brain Injury Center (DVBIC)<\/a>.<\/p>",
      "startDate": "2008-09-15T05:00:00Z",
      "endDate": "2020-03-14T05:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "Bob Woodruff Foundation",
      "newItem": false,
      "linkName": "http://remind.org/",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104756",
      "phoneNumber": "",
      "governmentSupportedSite": false,
      "content": "<p>Provides resources and support to injured Service Members, Veterans and their families, especially those who have sustained the hidden injuries of war.<\/p>",
      "startDate": "2008-08-22T05:00:00Z",
      "endDate": "2020-02-18T06:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "Brain Injury Network",
      "newItem": false,
      "linkName": "http://www.braininjurynetwork.org/",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104757",
      "phoneNumber": "",
      "governmentSupportedSite": false,
      "content": "<p>Provides advocacy, peer support, and resources for survivors of acquired brain injury (ABI), which includes traumatic brain injury (TBI), stroke, brain illness and brain tumors.<\/p>",
      "startDate": "2008-11-20T06:00:00Z",
      "endDate": "2020-05-19T05:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "BrainLine",
      "newItem": false,
      "linkName": "http://www.brainline.org/index.php",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104758",
      "phoneNumber": "",
      "governmentSupportedSite": false,
      "content": "<p>Provides a variety of information and resources on traumatic brain injury (TBI).<\/p>",
      "startDate": "2008-08-07T05:00:00Z",
      "endDate": "2020-02-03T06:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "Defense Centers of Excellence (DCoE)",
      "newItem": false,
      "linkName": "http://www.dcoe.health.mil/",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104759",
      "phoneNumber": "",
      "governmentSupportedSite": true,
      "content": "<p>Access a DoD program that works to improve psychological health and TBI treatment of Service Members and Veterans. <\/p>\n",
      "startDate": "2008-06-17T05:00:00Z",
      "endDate": "2020-12-14T06:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "Employment after Traumatic Brain Injury (TBI)",
      "newItem": false,
      "linkName": "http://biausa.fyrian.com/_literature_43314/employment_after_brain_injury",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104760",
      "phoneNumber": "",
      "governmentSupportedSite": false,
      "content": "<p>Learn about research and expectations regarding post-TBI vocational outcomes. Lists frequently asked questions and factsheets on employment options and useful information when living with a TBI.<\/p>",
      "startDate": "2008-05-11T05:00:00Z",
      "endDate": "2020-11-07T06:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "Facts About Traumatic Brain Injury (TBI)",
      "newItem": false,
      "linkName": "http://www.biausa.org/",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104761",
      "phoneNumber": "",
      "governmentSupportedSite": false,
      "content": "<p>Learn about TBI from the <a href=\"http://www.biausa.org\" target=\"_blank\">Brain Injury Association of America (BIAA)<\/a>. BIAA also offers an <a href=\"https://secure.biausa.org/OnlineDirectory/Directory/SearchType4.aspx\" target=\"_blank\">online directory<\/a> of brain injury rehabilitation programs and services across the US.<\/p>",
      "startDate": "2008-09-14T05:00:00Z",
      "endDate": "2020-03-13T05:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "Healthcare for Headaches",
      "newItem": false,
      "linkName": "http://www.headaches.org/",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104763",
      "phoneNumber": "",
      "governmentSupportedSite": false,
      "content": "<p>Provides educational and informational resources supporting headache research and treatment. The website provide articles that link headaches to TBI and PTSD.<\/p>",
      "startDate": "2009-03-30T05:00:00Z",
      "endDate": "2020-09-26T05:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "Project Victory",
      "newItem": false,
      "linkName": "http://www.projectvictory.org/",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104764",
      "phoneNumber": "",
      "governmentSupportedSite": false,
      "content": "<p>Helps Service Members who have sustained a mild to severe brain injury to regain skills and functions. <\/p>\n",
      "startDate": "2009-02-18T06:00:00Z",
      "endDate": "2020-08-17T05:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "Improved Treatment for Stuttering",
      "newItem": false,
      "linkName": "http://www.stutteringhelp.org/Default.aspx?tabid=4",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104765",
      "phoneNumber": "",
      "governmentSupportedSite": false,
      "content": "<p>Provides free online resources, services and support to those who stutter and their families, as well as support for research into the causes of stuttering.<\/p>",
      "startDate": "2009-03-30T05:00:00Z",
      "endDate": "2020-09-26T05:00:00Z",
      "interestGroups": [
        "Service Member",
        "Service Provider",
        "Family Member/Caregiver",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "Mild Traumatic Brain Injury (MTBI) Screening",
      "newItem": false,
      "linkName": "http://www.dvbic.org/research/mild-traumatic-brain-injury-screening-diagnosis-and-treatment",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104766",
      "phoneNumber": "",
      "governmentSupportedSite": true,
      "content": "<p>Access tool to identify Service Members who may need further evaluation for MTBI.<\/p>",
      "startDate": "2008-05-25T05:00:00Z",
      "endDate": "2015-11-21T06:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider",
        "Veteran"
      ],
      "geographicServiceLocations": [
        
      ],
      "subjects": [
        "Health"
      ]
    },
    {
      "title": "National Council on Disability - Report on the Invisible Wounds of TBI & PTSD",
      "newItem": false,
      "linkName": "http://www.ncd.gov/newsroom/publications/",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104767",
      "phoneNumber": "",
      "governmentSupportedSite": true,
      "content": "<p>Describes the less visible psychological and neurological injuries associated with post traumatic stress disorder (PTSD) or traumatic brain injury (TBI). Download a report titled <a href=\"http://www.ncd.gov/publications/2009/March042009\" target=\"_blank\">Invisible Wounds: Serving Service Members and Veterans with PTSD and TBI<\/a>.<\/p>",
      "startDate": "2009-03-04T06:00:00Z",
      "endDate": "2020-08-31T05:00:00Z"
    }

Open in new window

0
Bob LearnedCommented:
That JSON string doesn't map very well to your class, so I am confused what you are trying to extract from the string to display on a web page.
0
iNetBlazerAuthor Commented:
If you can assist me in mapping the below and creating a view I would be grateful.

 "subjects": [
        "Health"
      ]
    },
    {
      "title": "Army Behavioral Health",
      "newItem": false,
      "linkName": "http://www.behavioralhealth.army.mil/",
      "linkUrl": "https://www.nrd.gov/clickTrack/confirm/14104752",
      "phoneNumber": "",
      "governmentSupportedSite": true,
      "content": "<p>Learn about post-traumatic stress disorder (PTSD), <a href=\"http://www.behavioralhealth.army.mil/tools/faqschainteaching.html\">traumatic brain injury (TBI)<\/a> and suicide prevention. Includes help for <a href=\"http://www.behavioralhealth.army.mil/families/index.html\" target=\"_blank\">children, couples and extended families<\/a>.<\/p>",
      "startDate": "2008-05-25T05:00:00Z",
      "endDate": "2015-11-21T06:00:00Z",
      "interestGroups": [
        "Family Member/Caregiver",
        "Service Member",
        "Service Provider"
      ],
0
iNetBlazerAuthor Commented:
I tried the below on my own but it did not work.

public class NrdHealthMember
    {
        public string Title { get; set; }
        public string NewItem { get; set; }
        public string LinkURL { get; set; }
        public string PhoneNumber { get; set; }
        public string GovernmentSupportSite { get; set; }
        public string Content { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public string ServiceMember { get; set; }
        public string ServiceProvider { get; set; }
        public string Veterans { get; set; }
        public string State { get; set; }
        public string County { get; set; }
        public int Phone { get; set; }
        public string Address { get; set; }
        public string Health { get; set; }        

    }
0
iNetBlazerAuthor Commented:
public ActionResult GetNrdHealthInfo(string username, string password)
        {
            var healthApi = new NrdDataKey();
            healthApi.UserName = username;
            healthApi.Password = password;

            var client = new WebClient();
            client.Credentials = new NetworkCredential(username, password);
            //client.Headers.Add(username, password);
            var response = client.DownloadString(new Uri("https://www.nrd.gov/api/v1/topic/health"));
            var healthInfo = JsonConvert.DeserializeObject<NrdHealthMember>(response);

            List<NrdHealthMember> nrdHealthMember = new List<NrdHealthMember>();
            nrdHealthMember.Add(healthInfo);

            return View(nrdHealthMember);

        }
0
Bob LearnedCommented:
I used this JSON code generator to generate a class:

JSON C# Class Generator
http://jsonclassgenerator.codeplex.com/

It generates classes that you can use with Newtonsoft JSON serializer:

// Generated by Xamasoft JSON Class Generator
// http://www.xamasoft.com/json-class-generator

using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Example
{

    public class Resource
    {

        [JsonProperty("title")]
        public string Title { get; set; }

        [JsonProperty("newItem")]
        public bool NewItem { get; set; }

        [JsonProperty("linkName")]
        public string LinkName { get; set; }

        [JsonProperty("linkUrl")]
        public string LinkUrl { get; set; }

        [JsonProperty("phoneNumber")]
        public string PhoneNumber { get; set; }

        [JsonProperty("governmentSupportedSite")]
        public bool GovernmentSupportedSite { get; set; }

        [JsonProperty("content")]
        public string Content { get; set; }

        [JsonProperty("startDate")]
        public string StartDate { get; set; }

        [JsonProperty("endDate")]
        public string EndDate { get; set; }

        [JsonProperty("interestGroups")]
        public IList<string> InterestGroups { get; set; }

        [JsonProperty("geographicServiceLocations")]
        public IList<object> GeographicServiceLocations { get; set; }

        [JsonProperty("subjects")]
        public IList<string> Subjects { get; set; }
    }

    public class Sample
    {

        [JsonProperty("total_resources")]
        public int TotalResources { get; set; }

        [JsonProperty("page_size")]
        public int PageSize { get; set; }

        [JsonProperty("total_pages")]
        public int TotalPages { get; set; }

        [JsonProperty("current_offset")]
        public int CurrentOffset { get; set; }

        [JsonProperty("next_offset")]
        public int NextOffset { get; set; }

        [JsonProperty("previous_offset")]
        public int PreviousOffset { get; set; }

        [JsonProperty("resources")]
        public IList<Resource> Resources { get; set; }
    }

}

Open in new window

0
iNetBlazerAuthor Commented:
TheLearnedOne, I tried your suggestion and got the below error.  Also see code method below.

public ActionResult GetNrdHealthInfo(string username, string password)
        {
            var healthApi = new NrdDataKey();
            healthApi.UserName = username;
            healthApi.Password = password;

            var client = new WebClient();
            client.Credentials = new NetworkCredential(username, password);            
            var response = client.DownloadString(new Uri("https://www.nrd.gov/api/v1/topic/health"));
           
           var healthInfo = JsonConvert.DeserializeObject<List<NrdHealthMember>>(response);                      

            return View(healthInfo);

        }
0
iNetBlazerAuthor Commented:
Error below...

Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Demo.Models.NrdHealthMember]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.  Path 'total_resources', line 1, position 19.
0
Bob LearnedCommented:
Can you show me the class that you are working with, because the names are different than the sample code that I posted?

The JSON text is not a list, so you would need to deserialize to a single object (i.e. Sample in the example), and then retrieve the list from the property (i.e. Sample.Resources in the example).
0
iNetBlazerAuthor Commented:
public class NrdHealthMember
    {

        [JsonProperty("total_resources")]
        public int TotalResources { get; set; }

        [JsonProperty("page_size")]
        public int PageSize { get; set; }

        [JsonProperty("total_pages")]
        public int TotalPages { get; set; }

        [JsonProperty("current_offset")]
        public int CurrentOffset { get; set; }

        [JsonProperty("next_offset")]
        public int NextOffset { get; set; }

        [JsonProperty("previous_offset")]
        public int PreviousOffset { get; set; }

        [JsonProperty("resources")]
        public Resource[] Resources { get; set; }          
    }
0
iNetBlazerAuthor Commented:
public class Resource
    {

        [JsonProperty("title")]
        public string Title { get; set; }

        [JsonProperty("newItem")]
        public bool NewItem { get; set; }

        [JsonProperty("linkName")]
        public string LinkName { get; set; }

        [JsonProperty("linkUrl")]
        public string LinkUrl { get; set; }

        [JsonProperty("phoneNumber")]
        public string PhoneNumber { get; set; }

        [JsonProperty("governmentSupportedSite")]
        public bool GovernmentSupportedSite { get; set; }

        [JsonProperty("content")]
        public string Content { get; set; }

        [JsonProperty("startDate")]
        public string StartDate { get; set; }

        [JsonProperty("endDate")]
        public string EndDate { get; set; }

        [JsonProperty("interestGroups")]
        public string[] InterestGroups { get; set; }

        [JsonProperty("geographicServiceLocations")]
        public GeographicServiceLocation[] GeographicServiceLocations { get; set; }

        [JsonProperty("subjects")]
        public string[] Subjects { get; set; }        
    }
0
iNetBlazerAuthor Commented:
public class GeographicServiceLocation
    {
        [JsonProperty("state")]
        public string State { get; set; }

        [JsonProperty("county")]
        public string County { get; set; }

        [JsonProperty("city")]
        public string City { get; set; }

        [JsonProperty("phone")]
        public string Phone { get; set; }

        [JsonProperty("address")]
        public string Address { get; set; }      
    }
0
Bob LearnedCommented:
Try this:

var healthInfo = JsonConvert.DeserializeObject<NrdHealthMember>(response);  

return View(healthInfo.Resources.ToList());

Open in new window

0
iNetBlazerAuthor Commented:
Upon trying your suggestion I now get the below error...

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[myNameSpace.Models.Resource]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[myNameSpace.Models.NrdHealthMember]'.
0
Bob LearnedCommented:
I would change the view to use NrdHealthMember, and not IEnumerable<NrdHealthMember>.  Then, you can access the properties (like the Resources property).
0
iNetBlazerAuthor Commented:
How would I change the view to use NrdHealthMember?  Also, I'm trying to pass complex/multiple objects so why would I need to access the properties?
0
Bob LearnedCommented:
Can you show me the view, and explain what you are trying to do with it please?
0
iNetBlazerAuthor Commented:
What I'm trying to do is access the feed here >>> https://www.nrd.gov/home/api/resources

And display it in a view.

See view below.
0
iNetBlazerAuthor Commented:
@model IEnumerable<MyNameSpace.Models.NrdHealthMember>


@{
    ViewBag.Title = "GetNrdHealthInfo";
}

<h2>GetNrdHealthInfo</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            TotalResources
        </th>
        <th>
            PageSize
        </th>
        <th>
            TotalPages
        </th>
        <th>
            CurrentOffset
        </th>
        <th>
            NextOffset
        </th>
        <th>
            PreviousOffset
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>

        <td>
            @Html.Partial("_RootObject")
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.TotalResources)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PageSize)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.TotalPages)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.CurrentOffset)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.NextOffset)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PreviousOffset)
        </td>
       <td>
            @Html.Partial("_GeographicServiceLocation")
       </td>
       <td>
            @Html.Partial("_Resource")
       </td>
    </tr>
}

</table>
0
Bob LearnedCommented:
Let's try this:

1) NrdHealthMember has the following single properties (you don't need a for loop)(:

    TotalResources
    PageSize
    TotalPages
    CurrentOffset
    NextOffset
    PreviousOffset

2) There is an array of Resource objects, which has the following single properties.  You would use the for loop with these objects:

        Title
        NewItem
        LinkName
        LinkUrl
        PhoneNumber
        GovernmentSupportedSite
        Content
        StartDate
        EndDate

        These are array elements that need another for loop:

        InterestGroups
        GeographicServiceLocations
        Subjects
    }

3) The model definition should be changed to this:

@model MyNameSpace.Models.NrdHealthMember

4) The for loop should be changed to this:

@foreach (var item in Model.Resources)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
iNetBlazerAuthor Commented:
Thanks TheLearnedOne, your latest suggestion worked.  Just so that I have a better understanding of MVC and Json why did the IEnumerable<> need to be removed?  Is it because this Json object had nested arrays?  Or is it that Json objects cannot be deserialized as a List?  Or non of the above.

Again thank you for your help.  It is greatly appreciated.  I've learned something.
0
iNetBlazerAuthor Commented:
Thank you.
0
Bob LearnedCommented:
Or is it that Json objects cannot be deserialized as a List?   <<---- that one
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.