• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - Objc live Json Parsing Only 显示 1 项错误

[复制链接]
菜鸟教程小白 发表于 2022-12-12 17:10:45 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有工作 objc tableview 解析代码和实时条目。但显示仅匹配 1 行。我想显示所有匹配的行。我的工作代码在这里。

我的远程 json 文件

{
   "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"
}

Objc 代码在这里

#import "ViewController.h"
#import "Common/Constants.h"
#import "lace.h"

@interface ViewController (){
    NSMutableArray *response;
    Place *place;
    NSMutableArray *places;
}
@end


NSString *links;

@implementation ViewController
@synthesize toggleSwitch;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//    [self.txtSearchField becomeFirstResponder];
    self.tableViewSearchResult.hidden = YES;

     self.toggleSwitch.on = true;


        self.switchLabel.text = @"Coms";

        NSString *valueToSave = @"http://bla.com/company.php?";
        [[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey"preferenceName"];
        [[NSUserDefaults standardUserDefaults] synchronize];


}




- (IBAction)backChangeid)sender {
    if ([sender isOn] == YES) {
        _switchLabel.text = @"Firmalar";



        NSString *valueToSave = @"http://bla.com/company.php?";
        [[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey"preferenceName"];
        [[NSUserDefaults standardUserDefaults] synchronize];


        NSLog(@"");


    } else {


        NSString *valueToSave = @"http://bla.com/company2.php?";
        [[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey"preferenceName"];
        [[NSUserDefaults standardUserDefaults] synchronize];


  _switchLabel.text = @"Ülkeler";


        NSLog(@"");


          }






}





#pragma mark - 
-(void)searchForResultNSString *)input{


    NSString *savedValue = [[NSUserDefaults standardUserDefaults]
                            stringForKey"preferenceName"];


     NSString *urlString = [NSString stringWithFormat"%@gelen=%@",savedValue,input];

      NSLog(@"link = %@",urlString);

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];


}

#pragma mark - UITextField Delgate
-(BOOL)textFieldUITextField *)textField shouldChangeCharactersInRangeNSRange)range replacementStringNSString *)string{

    if (![string isEqualToString""] && [string length]>0) {
        NSString *keyword = [textField.text stringByAppendingString:string];
        NSLog(@"String : %@",keyword);
        if ([keyword length]>=4) {
            [self searchForResult:keyword];
        }
    }
    return YES;
}
#pragma mark - UITableViewDelegate 

-(void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath{
    place = [places objectAtIndex:indexPath.row];
    self.txtSearchField.text = place.placeName;
    NSLog(@"Selected placeID : %@",place.placeID);
    self.tableViewSearchResult.hidden = YES;
}

#pragma mark - UITableViewDataSource

-(UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier"cell"];

    if (nil == cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier"cell"];
    }
    place = [places objectAtIndex:indexPath.row];
    NSLog(@"lace ID : %@, Place Name : %@",place.placeID,place.placeName);
    cell.textLabel.text = [place placeName];
    return cell;
}
-(NSInteger)tableViewUITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [places count];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

当再匹配 1 个时给我这个错误(如果匹配 1 个成功显示)

Connection Error : (null)

我工作了大约 7-8 小时,但我没有解决它 我需要您的帮助,感谢您所做的一切。我认为这是一个简单的问题,但我仍然没有解决它。



Best Answer-推荐答案


你的json字符串应该是这样的

{
   "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"
}

满足您的代码并获得超过 1 个记录。

根据 RFC 4627(JSON 规范),它是一个有效的 josn。因此,您收到了 1 条回复。

关于ios - Objc live Json Parsing Only 显示 1 项错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33776037/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap