我有一个从 sqlite 检索的字符串
({
studentId = SUE1291ST;
studentName = "Student123Sdfw";
},
{
studentId = SUE13291ST;
studentName = "name123Sdfw";
})
如何转换为NSMutableArray
并获得NSDictionary
....?
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);
}
如果格式是 json (如您的标签所示),最简单的方法是使用NSJSONSerialization
使用
+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error
将为您返回一个基础类对象(NSArray,NSDictionary,取决于 json 数据)