如何在iOS中的核心数据中添加json解析数据?
这个我的数据解析代码解析完成后,将这些数据添加到核心数据中
- (void)DataRetireve {deatilinfoarray = [[NSMutableArray alloc] init]; NSURL * url = [NSURL URLWithString:@“http://sms.instatalkcommunications.com/apireq/GetSMSCategories?t=1&h=admin¶m=1”]; ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self]; [请求startAsynchronous]; }
(void)requestFinished:(ASIHTTPRequest *)request {
NSError *错误= [请求错误]; NSString * responseString = nil;
if(!error){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约束,那么你可以按照这个链接可能会帮助你。
链接地址: http://www.djcxy.com/p/68093.html上一篇: how to add json parse data in core data in iOS?
下一篇: ReliableMessaging interoperability between Microsoft WCF and iOS