我的一个应用程序,我从本地主机解析一些数据并将其打印在表格视图中。要获取数据,用户首先使用警报视图登录。然后使用输入的用户 ID 来获取我使用 JSON 解析的数据。
这个问题肯定有一个非常简单的解决方案,但我似乎无法解决它。问题是当我打印数据时,字符串以这种格式出现:
( “细绳” )
但我希望它只是说:字符串
在表格视图中。这是我的解析方法:
- (void)updateMyBooks
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Fetch data on a background thread:
NSString *authFormatString =
@"http://localhost:8888/Jineel_lib/bookBorrowed.php?uid=%@";
NSString *string = [[NSString alloc]initWithFormat:@"%@",UserID];
NSString *urlString = [NSString stringWithFormat:authFormatString, string];
NSURL *url = [NSURL URLWithString:urlString];
NSLog(@"uel is %@", url);
NSString *contents = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
response1 = [contents JSONValue];
if (contents) {
// ... Parse JSON response and add objects to newBooksBorrowed ...
BookName = [[NSString alloc]init];
DateBorrowed = [[NSString alloc]init];
BookID = [[NSString alloc]init];
BookExtended = [[NSString alloc]init];
BookReturned = [[NSString alloc]init];
BookName = [response1 valueForKey:@"BookName"];
BookID = [response1 valueForKey:@"BookID"];
DateBorrowed = [response1 valueForKey:@"DateBorrowed"];
BookExtended = [response1 valueForKey:@"Extended"];
BookReturned = [response1 valueForKey:@"Returned"];
dispatch_sync(dispatch_get_main_queue(), ^{
// Update data source array and reload table view.
[BooksBorrowed addObject:BookName];
NSLog(@"bookBorrowed array = %@",BooksBorrowed);
[self.tableView reloadData];
});
}
});
}
这就是我在表格视图中打印它的方式:
NSString *string = [[NSString alloc] initWithFormat:@"%@",[BooksBorrowed objectAtIndex:indexPath.row]];
NSLog(@"string is %@",string);
cell.textLabel.text = string;
当我在解析过程中使用日志时,它会显示为(“字符串”),所以问题出在解析的某个地方,至少我是这么认为的。