ios - Objc live Json Parsing Only 显示 1 项错误
<p><p>我有工作 objc tableview 解析代码和实时条目。但显示仅匹配 1 行。我想显示所有匹配的行。我的工作代码在这里。</p>
<p>我的远程 json 文件</p>
<pre><code>{
"company" : [
{
"description" : "example company , Jordan",
"id" : "90",
"place_id" : "90"
} {
"description" : "example company 2 , Qatar",
"id" : "362578",
"place_id" : "362578"
} {
"description" : "example company 3 , Spain",
"id" : "432589",
"place_id" : "432589"
},
{
"description" : " ",
"id" : "1",
"place_id" : "1"
}
],
"status" : "OK"
}
</code></pre>
<p>Objc 代码在这里</p>
<pre><code>#import "ViewController.h"
#import "Common/Constants.h"
#import "Place.h"
@interface ViewController (){
NSMutableArray *response;
Place *place;
NSMutableArray *places;
}
@end
NSString *links;
@implementation ViewController
@synthesize toggleSwitch;
- (void)viewDidLoad {
;
// Do any additional setup after loading the view, typically from a nib.
// ;
self.tableViewSearchResult.hidden = YES;
self.toggleSwitch.on = true;
self.switchLabel.text = @"Coms";
NSString *valueToSave = @"http://bla.com/company.php?";
[ setObject:valueToSave forKey:@"preferenceName"];
[ synchronize];
}
- (IBAction)backChange:(id)sender {
if ( == YES) {
_switchLabel.text = @"Firmalar";
NSString *valueToSave = @"http://bla.com/company.php?";
[ setObject:valueToSave forKey:@"preferenceName"];
[ synchronize];
NSLog(@"");
} else {
NSString *valueToSave = @"http://bla.com/company2.php?";
[ setObject:valueToSave forKey:@"preferenceName"];
[ synchronize];
_switchLabel.text = @"Ülkeler";
NSLog(@"");
}
}
#pragma mark -
-(void)searchForResult:(NSString *)input{
NSString *savedValue = [
stringForKey:@"preferenceName"];
NSString *urlString = ;
NSLog(@"link = %@",urlString);
NSURLRequest *request = ];
}
#pragma mark - UITextField Delgate
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
if (! && >0) {
NSString *keyword = ;
NSLog(@"String : %@",keyword);
if (>=4) {
;
}
}
return YES;
}
#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
place = ;
self.txtSearchField.text = place.placeName;
NSLog(@"Selected placeID : %@",place.placeID);
self.tableViewSearchResult.hidden = YES;
}
#pragma mark - UITableViewDataSource
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = ;
if (nil == cell) {
cell = [ initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"cell"];
}
place = ;
NSLog(@"Place ID : %@, Place Name : %@",place.placeID,place.placeName);
cell.textLabel.text = ;
return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return ;
}
- (void)didReceiveMemoryWarning {
;
// Dispose of any resources that can be recreated.
}
@end
</code></pre>
<p>当再匹配 1 个时给我这个错误(如果匹配 1 个成功显示)</p>
<pre><code>Connection Error : (null)
</code></pre>
<p>我工作了大约 7-8 小时,但我没有解决它 :) 我需要您的帮助,感谢您所做的一切。我认为这是一个简单的问题,但我仍然没有解决它。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你的json字符串应该是这样的</p>
<pre><code>{
"company" : [
{
"description" : "example company , Jordan",
"id" : "90",
"place_id" : "90"
}, {
"description" : "example company 2 , Qatar",
"id" : "362578",
"place_id" : "362578"
}, {
"description" : "example company 3 , Spain",
"id" : "432589",
"place_id" : "432589"
},
{
"description" : " ",
"id" : "1",
"place_id" : "1"
}
],
"status" : "OK"
}
</code></pre>
<p>满足您的代码并获得超过 1 个记录。 </p>
<p>根据 RFC 4627(JSON 规范),它是一个有效的 josn。因此,您收到了 1 条回复。</p></p>
<p style="font-size: 20px;">关于ios - Objc live Json Parsing Only 显示 1 项错误,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33776037/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33776037/
</a>
</p>
页:
[1]