代码之家  ›  专栏  ›  技术社区  ›  Matt S.

从NSDictionary获取字符串值

  •  1
  • Matt S.  · 技术社区  · 16 年前

    NSMutableDictionary *jsonObj = [parser objectWithString:json_string error:nil];
    NSString *test = [[[jsonObj objectForKey:@"questions"] valueForKey:@"owner"] valueForKey:key];
    

    但我得到的回报是:

     (
    1a19f089a2bc4ee42bff1c102c6e89b8
    )
    

    实际值很好,但是我得到了那些括号,它们显示在我的字符串中。我怎样才能摆脱他们?

    1 回复  |  直到 16 年前
        1
  •  1
  •   Georg Fritzsche    16 年前

    -stringByTrimmingCharactersInSet: 例如,一个 inverted alphanumeric character set 在这里工作应该很好:

    cleanStr = [str stringByTrimmingCharactersInSet:
                [[NSCharacterSet alphaNumericCharacterSet] invertedSet]];
    

    但实际上这听起来像是JSON的提供者或者解析器应该被修复。