How to parse a Json with 2 columns in Objective-C?

Asked

Viewed 104 times

0

In a Get using PHP I am making the request of 2 columns this way:

<?php
include 'conexao.php';
header('Content-Type: text/html; charset=UTF-8');
//Converte para UTF8 os resultados da query
mysql_set_charset('UTF8');
//Retorna resultado query idRegistro e updateatRegistro
$sql = "SELECT idRegistro,updateatRegistro FROM jump";
$resultado = mysql_query($sql) or die ("Erro: ".mysql_error());
// Crinha variável linha do tipo array
$linha = array();
  while($r = mysql_fetch_assoc($resultado))
    {  
        $linha [] = $r;
    }
 echo json_encode($linha);
mysql_close(); 
?>

And I’m trying to get the values. However, I realized that in responseData, I’m getting an answer with 2 layers of arrays and 1 dictionary:

thus:

1º Array |2º Array| Dicionario 
    [0] =    [0]    = idRegistro: 1;
             [1]    = updateAt: 2015/02/18 19:55:42;

When I try to extract the data from the first layer of the array, the return should be another array, but it is being recognized as a dictionary. I believe it is due to Json encoding.

I believe I should query these columns in another way. Someone could suggest a better way?

1 answer

1


After a few tests, I noticed that Xcode recognizes the second array as a dictionary, so I sent the message ...valueForKey:@"idRegitro"]; and he returned me the value correctly.

But I was amazed, because it seems to be a type recognition error, probably generated by the json Encode/Decode format, generated on the server and received by the native Json API in Xcode.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.