I have a function that receives a string, the string is a json, In which I need to validate the data of the json that send me to the function, this is my json, there is an array called eye products.
{"comprobante_tipo":1,"comprobante_emision":"10-05-2017","comprobante_moneda":2,"documento_tipo":6,"documento_numero":"20536161199","direccion":"Av.La Tienda de Charlie","nombre":"Cesar Vallejo","productos":[{"nombre":"Caramelos2","codigo":741,"cantidad":12,"unidad":"2","precio_unidad":2000},{"nombre":"Chocolates2","codigo":231,"cantidad":12,"unidad":"UNIDADES","precio_unidad":20002}]}
I wanted to deselate the json first, and put it in a dynamic, then validate it, and if everything was "fine", I made it and sent it to a webservice. But when trying the code below I get that I must apply a pointer.
if (x->comprobante_moneda.GetType() == typeof(int)) { } else { throw new Exception("Ingreso no Valido en Moneda"); }
Pass with this, and with the following
if (x.comprobante_tipo.GetType() == typeof(int)) { } else { throw new Exception("Ingreso no Valido en Tipo de Comprobante "); }
if (x.comprobante_emision.GetType() == typeof(string)) { } else { throw new Exception("Ingreso no Valido en Emision"); }
if (x.documento_tipo.GetType() == typeof(int)) { } else { throw new Exception("Ingreso no Valido en Tipo de Documento"); }
if (x.documento_numero.GetType() == typeof(string)) { } else { throw new Exception("Ingreso no Valido en Numero de Documento"); }
if (x.direccion.GetType() == typeof(string)) { } else { throw new Exception("Ingreso no Valido en Direccion"); }
if (x.nombre.GetType() == typeof(string)) { } else { throw new Exception("Ingreso no Valido en Nombre"); }
if (x.productos.codigo.GetType() == typeof(string)) { } else { throw new Exception("Ingreso no Valido en Productos"); }
if (x.productos.cantidad.GetType() == typeof(int)) { } else { throw new Exception("Ingreso no Valido en Cantidad"); }
if (x.productos.unidad.GetType() == typeof(int)) { } else { throw new Exception("Ingreso no Valido en Unidad"); }
if (x.productos.precio_unidad.GetType() == typeof(int)) { } else { throw new Exception("Ingreso no Valido en Precio de unidad"); }
What could I do? or what else should I try? Thanks