繁体   English   中英

如何在iOS的核心数据中添加json解析数据?

[英]how to add json parse data in core data in iOS?

我的数据解析代码解析完成了。如何将数据添加到核心数据中

-(void)DataRetireve {deatilinfoarray = [[NSMutableArray alloc] init]; NSURL * url = [NSURL URLWithString:@“ http://sms.instatalkcommunications.com/apireq/GetSMSCategories?t=1&h=admin&param=1 ”]; ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self]; [request startAsynchronous]; }

  • (void)requestFinished:(ASIHTTPRequest *)request {

    NSError * error = [请求错误]; NSString * responseString = nil;

    如果(!错误){responseString = [request responseString];

     SBJsonParser *parser = [[SBJsonParser alloc] init] ; NSMutableArray *jsondata = [parser objectWithString:responseString]; NSMutableArray *jsondata1 = [[NSMutableArray alloc]init]; for(int i=0;i<jsondata.count;i++) { info *myinfo=[[info alloc]init]; myinfo.Id=@"Id"; myinfo.Name=@"Name"; myinfo.IsActive=@"IsActive"; [jsondata1 addObject:myinfo]; NSLog(@"%@",responseString); } for(int i=0;i<jsondata1.count;i++) { info *myinfo= [jsondata1 objectAtIndex:i]; [jsondata1 addObject:myinfo]; } 

您使用它的最简单方法是-

int yPossion = 50, xPossion = 10; int temp = 0;
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
[self.view addSubview:scrollView];
for (int i = 0; i<50; i++){
    UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [aButton setBackgroundColor:[UIColor blackColor]];
    [aButton setBackgroundImage:[UIImage imageNamed:@"icon-menu.png"] forState:UIControlStateNormal];

    [aButton setTitle:[NSString stringWithFormat:@" %d",i] forState:UIControlStateNormal];
    [aButton setFrame:CGRectMake(xPossion, yPossion, 100, 50)];

    [scrollView addSubview:aButton];
    xPossion += aButton.frame.size.width+15;
    temp++;
    if (temp==3) {
        yPossion = aButton.frame.origin.y+aButton.frame.size.height+15;
        temp = 0;
        xPossion = 10;
        [scrollView setContentSize:CGSizeMake(scrollView.frame.size.width, yPossion+50)];
    }
}

但是,如果要使用autoLayout约束进行操作,则可以单击此链接,可能会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM