当前位置: 代码迷 >> Iphone >> 初学者请问字典里添加nsstring类型的字符串输出有有关问题---
  详细解决方案

初学者请问字典里添加nsstring类型的字符串输出有有关问题---

热度:208   发布时间:2016-04-25 06:53:06.0
菜鸟请教字典里添加nsstring类型的字符串输出有问题---急
textvalue 是:物品名称,申领数量;纸巾,2;铅笔,2;圆珠笔,2;

NSUInteger length = [textValue length];
  while ( [textValue length] != 0) {
   
  NSMutableDictionary *sheetDict = [[NSMutableDictionary alloc] initWithCapacity:10];
   
  NSInteger locoal = [textValue rangeOfString:@","].location;
  NSString *name = [textValue substringToIndex:locoal];
  NSLog(@"name0 %@", name);//在这打印name是:物品名称
  [sheetDict setObject:name forKey:@"name"];
   
   
  NSString *temp = [textValue substringFromIndex:locoal+1];
  textValue = temp;
  length = [textValue length];
  locoal = [textValue rangeOfString:@";"].location;
  NSString *value = [textValue substringToIndex:locoal];
  NSLog(@"value0 %@", value);//这里打印的value是:申请数量
  [sheetDict setObject:(NSString *)value forKey:@"value"];
  NSLog(@"sheetDict00 = %@", sheetDict);
  //这里打印字典里的数据就出现了
  {
  name = "\U7269\U54c1\U540d\U79f0";
  value = "\U7533\U9886\U6570\U91cf";
  },
不知道是为什么,请大侠指导。谢谢。
   
  temp = [textValue substringFromIndex:locoal+1];
  textValue = temp;
  NSLog(@"textvalue length = %d", [textValue length]);
   
  [sheetArray addObject:sheetDict];
  [sheetDict release];
   
  NSLog(@"sheetDict0 = %@", sheetDict);
  NSLog(@"sheetArray0 %@", sheetArray);

   
  }

------解决方案--------------------
字典里就是这样存储中文的,你像下面这样打印出来就是正确的:
NSLog(@"%@",[newDic valueForKey:@"value"]);
------解决方案--------------------
NSString * name = @"物品名称";
NSMutableDictionary * newDic = [[NSMutableDictionary alloc]initWithCapacity:10];
[newDic setObject:name forKey:@"value"];
lblTitle.text = [newDic objectForKey:@"value"];
NSLog(@"%@",[newDic objectForKey:@"value"]);
会有问题吗?我这样做正常的啊