您好我正在尝试从以下JSON文件(dataArray)中获取主题名称值,我已经通过NSJSONSERIALISATION运行:
-0: {
id: "55edc05848177ec741daf79e"
firstName: "Brad"
rating: 4.2
lessons: 5
text: "Lessons, they're yours take it"
-subjects: [4]
-0: {
name: "Indonesian"
pricePerHour: "500000"
}
-1: {
name: "Diving"
pricePerHour: "700000"
}
但是如果使用我用于其他元素的indexPath和点符号,则无法访问。我理解它必须因为我必须在两个数组中访问一个NSDictionary元素,但是却无法找到正确的代码来执行此操作(虽然这里看了很多,大多数示例都是为了更简单的情况)。 这是我一直在尝试的代码,但正如我所提到的,我现在看到这段代码没有涵盖JSON数组中的数组。我应该如何修改它以获得值:
// Load and display subjects
UILabel *subjectLabel = (UILabel *)[cell viewWithTag:103];
NSString * subject1String = [dataArray[indexPath.row] valueForKeyPath: @"subjects.0.name"];
subjectLabel.text = [NSString stringWithFormat:@"%@", subject1String];
答案 0 :(得分:0)
我认为这不是Json的有效证明。从服务器端获取打印响应。要获得 name:,您需要添加循环。