Xamarin Form Cross-Platform: Json Null reference exception

Jesus04FajardoJesus04Fajardo MXMember ✭✭
edited November 2017 in Cross Platform with Xamarin

I got this error:
System.NullReferenceException: Object reference not set to an instance of an object.

my code in c#:

 var postData = new List<KeyValuePair<string, string>>
                        new KeyValuePair<string, string>("correo", Application.Current.Properties["correo"].ToString())

                   var content = new FormUrlEncodedContent(postData);
                   HttpClient client = new HttpClient();

                   client.BaseAddress = new Uri("MyDirection");

                   var response = await client.PostAsync("php/request.php", content);
                   var result = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);

                   string nombre = JObject.Parse(result.ToString())["nombre"].ToObject<string>();
                   string apellido = JObject.Parse(result.ToString())["apellido"].ToObject<string>();
                   string telefono = JObject.Parse(result.ToString())["tel"].ToObject<string>();
                   string sexo = JObject.Parse(result.ToString())["sexo"].ToObject<string>();
                   string edad = JObject.Parse(result.ToString())["edad"].ToObject<string>();

And this is my php:

$email =  $_POST["correo"];

$sql= "SELECT * FROM agente WHERE email like '{$email}'";
$resultado = mysqli_query($link, $sql) or die("Consulta fallida:".mysqli_error($link));

while($fila = mysqli_fetch_assoc($resultado)) 
      $arreglo[] = array("nombre" => $fila ["nombre"], "apellido" => $fila ["apellido"], "tel" => $fila ["tel"], "sexo" => $fila ["sexo"], "edad" => $fila ["edad"]); 

echo json_encode($arreglo);

Can you help me please?

Best Answers


Sign In or Register to comment.