get rid of JSON variables symbols () [] {} for ObjectiveC variable

i'm trying to 'sql Select' information from TableWeb By -JSON code-

in xCode, when i "NSLog" the information it's looks like that: i'm tryng to get rid of those symbols () []. how can i receive only the The variable value? thank you all

2012-06-13 12:24:54.572 Gym31Vads[5628:16103] (
    204
)

2012-06-13 12:33:33.911 Gym31Vads[5628:16103] (
    204
)

2012-06-13 12:35:12.830 Gym31Vads[5628:16103] (
    204
)

here is my JASON code on the Web:

$var_email=$_POST['mail'];
$query = mysql_query(" SELECT `pk` FROM `adidas` WHERE `mail` = ('{$var_email}') LIMIT 1);
$users = array();
while ($row = mysql_fetch_array($query))
{ 
    $users = array($row['pk']);
}
echo json_encode($users);

here is the ObjectiveC code:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];        
NSString * urlString = [NSString stringWithFormat:@"myURLselectPK.php"];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString*paramDataString=[NSString stringWithFormat:@"mail=%@",txt_mail.text];
NSData*paramData=[paramDataString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:paramData];
NSURLResponse *response;
NSError *error;

NSData *aData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

NSURL*url=[NSURL URLWithString:@"myURLselectPK.php"];

NSData*data=[NSData dataWithContentsOfURL:url];

NSError*err=nil;
NSMutableDictionary*jsondict=[NSJSONSerialization JSONObjectWithData:aData options:kNilOptions error:&err];

NSMutableArray*json=(NSMutableArray*)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&err];

NSLog(@"%@",jsondict);

NSError *error2; 
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsondict 
                                                       options:NSJSONWritingPrettyPrinted 
                                                         error:&error2];
NSString*Str=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSString*str_screen=[NSString stringWithFormat:@"%@",Str];

lbl_pk_check.text=[NSString stringWithFormat:@"%@",Str];

Answers


NSLog shows ( ) around your variable to denote that it's the array you're printing. If you want to display only the value that's inside of the array, you must first fetch it, whether by key if you're using dictionary or by index if you're printing an array.

Anyhow, you seem to be putting too much attention towards what you show in NSLog. What shows there isn't the real value of your variable, but just a string representation to show in the log. In reality, your variable won't have any of the ( ) or [ ] symbols, but only 204 enclosed in the array container.

On a side note, you are printing NSMutableDictionary *jsondict variable, but in reality you have an array inside. That JSON deserialisation method you're using has returned a (most likely) immutable array, and you should've assigned it to NSArray *variable. If you want a mutable object, you must call [NSMutableArray arrayWithArray:] method, you cannot simply cast one to another.


NSLog is a diagnostic tool. You don't have any options as to how it formats objects with the %@ specifier. If you want some other format, you need to build up the string yourself. For instance, to log the content of an array without the parentheses:

NSMutableString* logString = [[NSMutableString alloc] init];
for (id anObject in myArray)
{
    if ([logString length] > 0)
    {
        [logString appendString: @", "]; 
    }
    [logString appendString: [anObject description]];
}
NSLog(%@", lofString);

You can't do anything about this stuff:

2012-06-13 12:35:12.830 Gym31Vads[5628:16103] 

at all.


Need Your Help

Paver 0.8.1 compatibility with python 2.6

python bootstrapper build-environment

Does anyone manage to bootstrap its development area using paver with python 2.6 ?