[Objective-C] JSON转NSDictionary后遍历多维的NSDictionary →→→→→进入此内容的聊天室

来自 , 2019-03-06, 写在 Objective-C, 查看 163 次.
URL http://www.code666.cn/view/29fdff89
  1. - (NSString *)stringFormDict:(NSDictionary*)dict
  2.  {
  3.      NSMutableString *str = [NSMutableString string];
  4.      NSArray *keys = [dict allKeys];
  5.      for (NSString *key in keys) {
  6.          if ([[dict objectForKey:key] isKindOfClass:[NSDictionary class]]) {
  7.              id obj = [dict objectForKey:key];
  8.              [str appendFormat:@"\n%@: %@",key,[self stringFormDict:obj]];
  9.          }else if ([[dict objectForKey:key] isKindOfClass:[NSArray class]]){
  10.              [str appendFormat:@"\n%@:",key];
  11.              for (id obj in [dict objectForKey:key]) {
  12.                  [str appendFormat:@"\n%@",[self stringFormDict:obj]];
  13.              }
  14.          }else{
  15.              [str appendFormat:@"\n%@: %@",key,[dict objectForKey:key]];
  16.          }
  17.      }
  18.      return str;
  19.  }
  20. //objectc/5093

回复 "JSON转NSDictionary后遍历多维的NSDictionary"

这儿你可以回复上面这条便签

captcha