I have a code that access a Api link and retrieves that Json values and stores them in a object list. However when there is nothing to retrieve (Link to the Api doesnt exist) it returns nothing.
However even though the Api link is wrong it still returns Json values. These are their default values that will always be there even though there is nothing that matches the ID requested.
Below link will show values that will always return no matter what
here is where i call to the Api
var spidyApi_idByName_result = api_Handler.objFromApi_nameToId(spidyApi_searchIdByName);
Here the Api is accessed and the Json is deserialized.
public RootObject objFromApi_nameToId(string url){
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
try{
WebResponse response = request.GetResponse();
using (Stream responseStream = response.GetResponseStream()){
StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
var jsonReader = new JsonTextReader(reader);
var serializer = new JsonSerializer();
return serializer.Deserialize<RootObject>(jsonReader);
}
}
catch (WebException){
throw;
// used throw as otherwise i can not run code, function requires every path to return
// Catch never gets called
}
}
RootObject class
public RootObject GetApi(string url)
{
// ...
return serializer.Deserialize<RootObject>(jsonReader);
}
How do i go around and ignore their "default" json values? just do nothing.
public int count { get; set; }