试图找出为什么从 tableviewcontroller 到Detailviewcontroller 的 json segue 不起作用。做了 NSLog 来查看数据是否通过,这就是 dvc 中显示的内容。
"data.detail" NSLog:
(
{
emails = {
10 = j;
11 = k;
12 = l;
9 = i;
};
links = {
1 = a;
2 = b;
3 = c;
4 = d;
};
location = {
13 = m;
14 = n;
15 = o;
16 = p;
};
numbers = {
5 = e;
6 = f;
7 = g;
8 = h;
};
}
)
然后我...
尝试将json数据转换为detailviewcontroller中的tableview。
NSString *rawString = [NSString stringWithFormat:@"%@", data.detail];
NSString *jsonString = rawString;
NSData *JSONdata = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *jsonError = nil;
但是将 JSON 转换为 NSData 后,NSDictionary 只会在 NSLog 中输出“null”。
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:JSONdata options:0 error:&jsonError];
NSArray *items = [dic valueForKeyPath:@"email"];
NSLog(@"dic %@", dic);
NSLog(@"items %@", items);
帮助!非常感谢。
最佳答案
更改以下代码行
NSArray *items = [dic valueForKeyPath:@"email"];
到
NSArray *items = [dic valueForKeyPath:@"emails"];
如果你仍然得到 nslog nil 而不是改变
NSString *rawString = [NSString stringWithFormat:@"%@", data.detail];
喜欢这个
NSString *rawString = @"{\"emails\" :{\"10\" : \"j\",\"11\" : \"k\",\"12\" : \"l\",\"9\" : \"i\"},\"links\" :{\"1\" : \"a\",\"2\" : \"b\",\"3\" : \"c\",\"4\" : \"d\"}}";
关于ios - 在 DetailViewController 中将 JSON 字符串转换为 NSDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27226917/