我从Web服务获取数据,我将它放到NSDictionary
,并且通过使用valueForKey
方法,我将数据绑定到一个数组中,它有17个元素,但计数显示为1,因为第一个数据有双引号。这是示例代码:
- (void)BarChartfetchedData:(NSData *)responseData {
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
BarChartDictionary = [json objectForKey:@"Report_DashboardDetailProfitBranchResult"];
NSArray * new = [[NSArray alloc]initWithObjects:[BarChartDictionary valueForKey:@"ProfitAmount"],nil];
NSLog(@"mypieclass.itemArray: %@ ",new);
NSLog(@"Total: %lu ",(unsigned long)[new count]);
NSLog(@"BarChartDictionary: %lu ",(unsigned long)[BarChartDictionary count]);
}
需要获得总数17.如何做到这一点,任何建议都会有所帮助。
答案 0 :(得分:2)
尝试
NSArray * new = [[NSArray alloc]initWithArray:[BarChartDictionary valueForKey:@"ProfitAmount"]]; // if not using ARC you will have to release it.
或只是
NSArray *new = BarChartDictionary[@"ProfitAmount"];
芝麻街手木偶解释:
( // <- begin top level array
( // <- begin first element in top level array. it is another array, a nested array
"16291443.69", // <- first element in the nested array
6621797, // <- second element in the nested array
5692671,
2477348,
2362607,
2281261,
886410,
848799,
762441,
706688,
497076,
492402,
188320,
124595,
96625,
62905,
60200 // <- last element in the nested array
) // <- end first element in top level array
) // <- end top level array
- &GT;顶级数组只有元素。这是另一个有17个元素的数组。
答案 1 :(得分:0)
字典对象是否正确打印,其中包含17值?如果字典本身是正确的,您可能需要以不同的方式解析字典中的count对象。
可能是您使用错误的格式打印计数,因为它实际上不是很长的无符号...因为您将其转换为long unsigned,编译器将不会显示警告... < / p>