I am having trouble with an if statement for checking if an object is null.
I have a webClient go and pull a JSON string from a website in a try/catch. If it errors, it is because the 3 digit country does not exist in the API and I just want to skip it.
Here is my code:
System.Net.WebClient wc = new System.Net.WebClient();
RootObject ro;
try
{
string resp = wc.DownloadString("https://restcountries.eu/rest/v2/alpha/" + Row.Code.ToString());
JavaScriptSerializer js = new JavaScriptSerializer();
ro = js.Deserialize<RootObject>(resp);
}
catch (Exception e)
{ }
if (ro.Region != null)
{
Row.Region = ro.Region;
Row.SubRegion = ro.Subregion;
}
RootObject is a class to deserialize to. This works fine.
However, I am getting an error in the if statement that "use of unassigned class 'ro'.
Can someone help me fix this? ro works as expected inside the if?
I have also tried checking a specific node and it is still getting hung up on the 'ro' part.
Also, this is a script component in SSIS.
Thanks