我正在尝试将JSON输出准备到iOS中的数组中。但阵列根本没有被填满。以下是相关代码:
- (void) retrieveData;
{
NSString *getDataURL = @"http://localhost:8888/finalproject/ios/getHouseBills.php";
NSURL * url = [NSURL URLWithString:getDataURL];
NSData * data = [NSData dataWithContentsOfURL:url];
jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
houseBillsArray = [[NSMutableArray alloc] init];
long test = jsonArray.count;
for(int i = 0; i < jsonArray.count; i++)
{
NSString * hBID = [[jsonArray objectAtIndex:i] objectForKey:@"houseBillID"];
NSString * hID = [[jsonArray objectAtIndex:i] objectForKey:@"houseID"];
NSString * hName = [[jsonArray objectAtIndex:i] objectForKey:@"name"];
NSString * hAmount = [[jsonArray objectAtIndex:i] objectForKey:@"amount"];
NSString * hDate = [[jsonArray objectAtIndex:i] objectForKey:@"date"];
NSString * hAddedBy = [[jsonArray objectAtIndex:i] objectForKey:@"addedBy"];
[houseBillsArray addObject:[[House alloc]initWithHouseBillID:hBID andHouseID: hID andName: hName andAmount: hAmount andDate: hDate andAddedBy: hAddedBy]];
}
[self.tableView reloadData];
[self.refreshControl endRefreshing];
}
以下是它将采用的JSON输入示例:
[{"houseBillID":"1","houseID":"20","name":"Loo roll","amount":"32453","date":"eqferf","addedBy":"samstone920@googlemail.com"},{"houseBillID":"2","houseID":"20","name":"toothpaste","amount":"3","date":"wefe","addedBy":"44tq"}]
请原谅,这主要是胡言乱语。但是,阵列根本没有被填满。有些东西告诉我它的字符集,但我不确定。
任何帮助都非常感激。
编辑:我尝试解析JSON raw,这很好。
编辑:数据检索正常。只是NSLog的数据变量。