JSON ARRAY TO LIST TO GRIDVIEW

Loop through a JSON array to put into a list so that I can use the list in a grid. Here is what I have thus far. I'm using C# and needing to get all information at index 0 and put that in a grid row, then index 1, index 2 and so forth. I have some code as shown below and have also attached the JSON file for reference.

protected void GetNPInformation()
        {
            string searchUrl = "https://npiregistry.cms.hhs.gov/api/resultsDemo2/";
            string searchCritera = "?city=baltimore";
            //string returnFileFormat = "&rt=json";


            string fullSearchPath = searchUrl + searchCritera;

            //Get search results back in JSON format.
            string jsonData = new WebClient().DownloadString(fullSearchPath);
            
           
            //Read all items
            var path = Server.MapPath(@"~/json-test.json");
            var root = JsonConvert.DeserializeObject<RootObject>(jsonData);
            var taxonomies = root.results[0].taxonomies;
            var basic = root.results[0].basic;
            var address = root.results[0].addresses;
            

        }

        public class Taxonomy
        {
            public string state { get; set; }
            public string code { get; set; }
            public bool primary { get; set; }
            public string license { get; set; }
            public string desc { get; set; }
        }

        public class Address
        {
            public string city { get; set; }
            public string address_2 { get; set; }
            public string telephone_number { get; set; }
            public string fax_number { get; set; }
            public string state { get; set; }
            public string postal_code { get; set; }
            public string address_1 { get; set; }
            public string country_code { get; set; }
            public string country_name { get; set; }
            public string address_type { get; set; }
            public string address_purpose { get; set; }
        }

        public class Basic
        {
            public string status { get; set; }
            public string credential { get; set; }
            public string first_name { get; set; }
            public string last_name { get; set; }
            public string middle_name { get; set; }
            public string name { get; set; }
            public string sole_proprietor { get; set; }
            public string gender { get; set; }
            public string last_updated { get; set; }
            public string name_prefix { get; set; }
            public string enumeration_date { get; set; }
            public string authorized_official_telephone_number { get; set; }
            public string parent_organization_legal_business_name { get; set; }
            public string authorized_official_middle_name { get; set; }
            public string authorized_official_last_name { get; set; }
            public string organization_name { get; set; }
            public string organizational_subpart { get; set; }
            public string authorized_official_title_or_position { get; set; }
            public string parent_organization_ein { get; set; }
            public string authorized_official_first_name { get; set; }
        }

        public class Result
        {
            public List<Taxonomy> taxonomies { get; set; }
            public List<Address> addresses { get; set; }
            public int created_epoch { get; set; }
            public List<object> identifiers { get; set; }
            public List<object> other_names { get; set; }
            public int number { get; set; }
            public int last_updated_epoch { get; set; }
            public Basic basic { get; set; }
            public string enumeration_type { get; set; }
        }

        public class RootObject
        {
            public int result_count { get; set; }
            public List<Result> results { get; set; }
        }

    }
}

Open in new window

Trent AdamsApplication EngineerAsked:
Who is Participating?
 
Trent AdamsConnect With a Mentor Application EngineerAuthor Commented:
I'm not sure why the attachment didn't attach. However, I think I'm closing the question as I should be able to use the JSON file as is.
0
 
NorieVBA ExpertCommented:
Trent

I'm afraid there's no attachment.
0
 
Trent AdamsApplication EngineerAuthor Commented:
The more research that I did regarding this file showed that I shouldn't have to perform additional tasks to utilize the JSON file. By taking the the JSON data and putting into another list is counter productive and would create unnecessary code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.