John Riker

John Riker

  • NA
  • 85
  • 14.3k

JSON Feed an no values

Nov 29 2020 5:03 PM
Have a program that calls up a URL of JSON data and loads it in and then starts processing it record by record.  That said, sometimes the result can be just a header with no data for various reasons.  When I try to process the results I end up getting the below due to no data:
  1. Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.  
  2. at ShowWebsiteDownloader.Program.Main() in C:\Users\jriker\source\repos\ShowWebsiteDownloader\ShowWebsiteDownloader\Program.cs:line 97  
 So I read in the data:
 
  1. rawJSON = webClient.DownloadString(showsurls);  
  2. ShowWebsiteDownloader.Rootobject rootObject = JsonConvert.DeserializeObject<ShowWebsiteDownloader.Rootobject>(rawJSON);   
 
Then process the results 
  1. for (int loop = 0; loop < rootObject.tiles.Length; loop++)  
  2.  {    
 So the before mentioned error is on the start of the for loop.  Is there a way to check if any data exists after Deserializing?
 
 

Answers (4)