當我收到來自JSON的PHP然後我得到問題的__NSCFBoolean isEqualToString值:__NSCFBoolean isEqualToString:]:無法識別的選擇發送到實例
我的代碼如下:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//convert to JSON
for(id key in res) {
id value = [res objectForKey:key];
NSString *keyAsString = (NSString *)key;
NSString *valueAsString = (NSString *)value;
//NSCFBoolean
/*if([value isKindOfClass:[NSNumber class]])
{
printf("Number");
}
else if([value isKindOfClass:[NSString class]])
{
printf("String --- \n");
if([value isEqualToString:@"0"])
{
printf("Wrong \n");
}
else
{
printf("Right \n");
}
}*/
NSLog(@"%@",[valueAsString class]);
if([keyAsString isEqualToString:@"success"])
{
printf("Working \n");
}
else
{
printf("Not Working\n");
}
//Error is in below line
if([valueAsString isEqualToString:@"0"])// strcmp([value objCType], @encode(BOOL)) == 1)
{
[self loginSuccess];
}
else if(strcmp([value objCType], @encode(BOOL)) == 0)
{
[self loginFailure];
}
NSLog(@"key: %@", keyAsString);
NSLog(@"value: %@", valueAsString);
}
} }
獲得[__NSCFBoolean isEqualToString:]:的問題無法識別的選擇發送到實例0x1dc9964
Searchi Google從昨天開始處理這個問題,但還沒有解決方案。現在,NSCFBoolean在iOS 6.0中也不可用。那麼我能做些什麼來檢查JSON字符串中的「0」或「1」?請幫忙。
我也試過一樣,但沒有工作。 :( – VarunJi
'[valueAsString isEqualToString:@「0」]''[value boolValue] == 0' –
'[value boolValue] == NO'會更好,'![value boolValue]'最好 –