我正在使用Json Parsing进行自我提示
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
autoCompleteTable.hidden = NO;
NSString *substring = [NSString stringWithString:textField.text];
substring = [substring stringByReplacingCharactersInRange:range withString:string];
if(substring.length>=3)
{
[self getDescriptionData];
[self searchAutocompleteEntriesWithSubstring:substring];
}
else {
[placesArray removeAllObjects];
[autoCompleteTable reloadData];
}
return YES;
}
在getDescription方法中检索JSON值。但当它被称为第二齿时我得到错误: -JSONValue失败。错误跟踪是:( “Error Domain = org.brautaset.JSON.ErrorDomain Code = 10 \”JSON后的垃圾\“UserInfo = 0x4b60160 {NSLocalizedDescription = JSON后的垃圾}” )
答案 0 :(得分:0)
所以我决定改用JSONKit: (github:https://github.com/johnezang/JSONKit)
// sbjson
// NSString *jsonStr = [NSString stringWithCString:[receivedData bytes]
// encoding:NSUTF8StringEncoding];
// NSArray *returnArr = [jsonStr JSONValue];
// jsonkit
JSONDecoder *decoder = [JSONDecoder decoder];
NSError *error;
NSArray *returnArr = [decoder objectWithData:receivedData error:&error];
最后,这有效。