Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle error converting {null} to type system.Int32 in input json

Platform : C# IDE : Microsoft Visual Studio 2010

I am new to Json and wondering on how to handle the error converting value {null} to type system.Int32 in an input. Any suggestion?

like image 981
Harsh Kumar Singhi Avatar asked Jun 29 '15 07:06

Harsh Kumar Singhi


2 Answers

Another option is to ignore null values.

JsonConvert.DeserializeObject<YourType>(jsonText, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
like image 140
nkanani Avatar answered Nov 06 '22 01:11

nkanani


You could use replace your Int32s with their nullable counterpart using int? . You can find more about nullable types here.

like image 35
Nasreddine Avatar answered Nov 06 '22 01:11

Nasreddine