sharkyenergy
sharkyenergy

Reputation: 4173

Xamarin - Deserialize empty Json

I have following code to deserialize a Json String.

var deserializedUrl = JsonConvert.DeserializeObject<galURL>(GalUrl);

Problem is, if the user entered a invalid code, the returned Json string is empty.. its simply [].

The app crashes.. What would be a proper way to solve this? I'd add a try/catch but maybe there is a better way to solve this.

Upvotes: 0

Views: 22

Answers (1)

Rajendra Razz
Rajendra Razz

Reputation: 209

Please check below code

        var settings = new JsonSerializerSettings
        {
            NullValueHandling = NullValueHandling.Ignore,
            MissingMemberHandling = MissingMemberHandling.Ignore
        };
        try
        {
          var data = Newtonsoft.Json.JsonConvert.DeserializeObject<galURL>(GalUrl,settings);                    
        }
        catch (Exception ex)
        {
        }

Upvotes: 1

Related Questions