字符串数组值为ios中的NSMutableArray

时间:2013-09-13 07:21:12

标签: ios nsstring nsarray

我有从sqlite

检索的字符串
({ 
    studentId = SUE1291ST;
    studentName = "Student123Sdfw"; 
  }, 
  { 
    studentId = SUE13291ST;
    studentName = "name123Sdfw";
 })

如何转换为NSMutableArray并获取NSDictionary ....?

2 个答案:

答案 0 :(得分:0)

如果格式为json(正如您的代码所示),最简单的方法是使用NSJSONSerialization

使用

+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error

会给你一个返回的基础类对象(NSArray,NSDictionary,取决于json数据)

答案 1 :(得分:0)

u want dict values from array..so

 dataArray =[NSMutableArray array];
    NSMutableDictionary *dic =[[NSMutableDictionary alloc]init];
    [dic setObject:@"SUE1291ST" forKey:@"studentId"];
    [dic setObject:@"Student123Sdfw" forKey:@"studentName"];

    [dataArray addObject:dic];

     dic =[[NSMutableDictionary alloc]init];
    [dic setObject:@"SUE13291ST" forKey:@"studentId"];
    [dic setObject:@"name123Sdfw" forKey:@"studentName"];

    [dataArray addObject:dic];

    NSLog(@"dataArray:%@",dataArray);

    for (NSDictionary *dic in dataArray) {

        NSLog(@"DICTIONARY IS:%@",dic);
    }