【问题标题】:-JSONValue Failed error trace is:Garbage after JSON-JSONValue 失败的错误跟踪是:JSON 后的垃圾
【发布时间】:2012-08-21 17:58:18
【问题描述】:

我正在使用 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 失败。错误跟踪是:( “错误域=org.brautaset.JSON.ErrorDomain 代码=10 \"JSON 后的垃圾\" UserInfo=0x4b60160 {NSLocalizedDescription=JSON 后的垃圾}" )

【问题讨论】:

  • 当我在文本字段中输入 3 个字符时,它会调用 JSON Parser & 工作正常,但是当我在文本字段中输入下一个字符时,它会给出错误:JSON 之后的垃圾。

标签: iphone json


【解决方案1】:

我遇到了同样的事情。 在谷歌搜索和堆栈流之后,我什么也没找到。

所以我决定改用 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];

终于,这行得通了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多