我正在解析的 JSON 可以在这里找到“已编辑”。
我可以正确地从这个 JSON 中获取除通知和设备之外的所有对象。我在获取包含“deviceId”的设备字典数组时遇到了很多麻烦。我的代码现在看起来像这样
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:
iViuListOfCustomersURL];
[self performSelectorOnMainThread:@selector(fetchedData:)
withObject:data waitUntilDone:NO];
});
- (void) fetchedData:(NSData *)responseData {
NSError* error;
NSDictionary* json;
json = [NSJSONSerialization
JSONObjectWithData:responseData // 1
options:kNilOptions
error:&error];
NSArray* customers = json;
for(int i = 0; i < customers.count ; i++){
NSDictionary *customer = [customers objectAtIndex:i];
cmsServer = [customer objectForKey:@"cmsServer"];
iconUrl = [NSURL URLWithString:[customer objectForKey:@"iconUrl"]];
wideLogo = [customer objectForKey:@"wideLogo"];
customerNo = [NSNumber numberWithInt:[[customer objectForKey:@"customerNo"] intValue]];
placeName = [customer objectForKey:@"placeName"];
distance = [NSNumber numberWithFloat:[[customer objectForKey:@"distance"] floatValue]];
placeId = [NSNumber numberWithInt:[[customer objectForKey:@"placeId"] intValue]];
address = [customer objectForKey:@"address"];
cmsName = [customer objectForKey:@"cmsName"];
hasLocations = [NSNumber numberWithInt:[[customer objectForKey:@"hasLocations"]intValue]];
isFavorite = [NSNumber numberWithInt:[[customer objectForKey:@"isFavorite"] intValue]];
longitude = [NSNumber numberWithFloat:[[customer objectForKey:@"longitude"] floatValue]];
latitude = [NSNumber numberWithFloat:[[customer objectForKey:@"latitude"] floatValue]];
hasArtifacts = [NSNumber numberWithInt:[[customer objectForKey:@"hasArtifacts"]intValue]];
// I have tried a number of things and this was what I had for the last try.
devices = [NSArray arrayWithObject:[customer objectForKey:@"devices"]];
NSLog(@"%@",devices.count);
}
}
我对objective-c比较陌生,想自己解决这个问题,但我在这个问题上花了太多时间,没有这些设备ID我无法继续。
谢谢!