Hi Guys
I really appreciate the help parsing out this JSON result
{"result_count":1,"results":[{"created_epoch":"1151241154000","enumeration_type":"NPI-1","last_updated_epoch":"1630682512000","number":"1427084888","addresses":[{"country_code":"US","country_name":"United States","address_purpose":"LOCATION","address_type":"DOM","address_1":"6101 WEBB RD STE 301","city":"TAMPA","state":"FL","postal_code":"336152866","telephone_number":"813-885-3600","fax_number":"813-885-4600"},{"country_code":"US","country_name":"United States","address_purpose":"MAILING","address_type":"DOM","address_1":"6101 WEBB RD STE 301","city":"TAMPA","state":"FL","postal_code":"336152866"}],"practiceLocations":[],"basic":{"first_name":"ALEJANDRO","last_name":"CINTAS","middle_name":"R","credential":"MD","sole_proprietor":"NO","gender":"M","enumeration_date":"2006-06-25","last_updated":"2021-09-03","certification_date":"2021-09-03","status":"A"},"taxonomies":[{"code":"207R00000X","taxonomy_group":"","desc":"Internal Medicine","state":"FL","license":"ME0080234","primary":false},{"code":"207Q00000X","taxonomy_group":"","desc":"Family Medicine","state":"FL","license":"ME80234","primary":true}],"identifiers":[{"code":"05","desc":"MEDICAID","issuer":null,"identifier":"259401300","state":"FL"}],"endpoints":[],"other_names":[]}]}
Here it is my code I only posting a few of the result but I would like to get them all value from the JSON string.
Physicians DoctorInfo = new Physicians();
string info = new WebClient().DownloadString(apiUrl);
JavaScriptSerializer jsonObject = new JavaScriptSerializer();
DoctorInfo = jsonObject.Deserialize(info);
//- Result values are coming as null for all the properties
Console.WriteLine(DoctorInfo.number);
internal class Physicians
{
public string first_name { get; set; }
public string last_name { get; set; }
//country
public string country_code { get; set; }
public string country_name { get; set; }
public string city { get; set; }
public string state { get; set; }
public string postal_code { get; set; }
public string telephone_number { get; set; }
public string fax_number { get; set; }
public string number { get; set; }
public string TimeZone { get; set; }
}
Thanks
JS.
Vishal YelvePosted Oct 23, 2023, 6:12 AM
Hi Jose,
Try this
Jose SaizPosted Oct 23, 2023, 11:05 AM
Thank you guys for all your help, I was wondering why I was getting result value as null, now I see why I was not parsing out the JSON file correctly, I needed to split the file by [Result], [Basic], [Address], [Taxonomy] etc, I thanks very much Vishal Yelve and Muhammad Imran Ansari for the great explanation which worked 100% and for letting know HOW TO. I've parsed JSON before but just simple straight forward not like this one with so many levels.
I also thanks Sam and Vishal for their replies.
Guys I really appreciate all your help.
Vishal JoshiPosted Oct 23, 2023, 6:00 AM
Hello
To parse dynamic JSON in C#, you can use the System.Text.Json.JsonDocument class provided by the System.Text.Json namespace, which is available in .NET Core and .NET 5.
Here's an example of how to parse dynamic JSON using JsonDocument:
Thanks
Vishal Joshi
Sam HobbsPosted Oct 22, 2023, 9:22 PM
In Visual Studio open or create a C# file (cs extension). Copy some sample JSON (such as what you posted here) to the clipboard. In Visual Studio, in the Edit menu, Choose "Paste Special" | "Paste JSON As Classes". VS will generate the classes you need. Then you can use the .Net classes in the System.Text.Json namespace or the classes in the Newtonsoft library to parse JSON.
Muhammad Imran AnsariPosted Oct 22, 2023, 9:02 PM
To parse the provided json, use the following class structure: