【发布时间】:2013-04-22 21:07:38
【问题描述】:
我创建了一个应用程序,我从 JSON 中读取了 table View 中的许多数据,我想解析这个 JSON 并存储在 sqlite 中,但我不知道我应该从哪里开始?
这是解析我的 json 代码:
@implementation TableViewController
{
NSArray *news;
NSMutableData *data;
NSString *title;
NSMutableArray *all;
}
@synthesize mainTable;
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"News";
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSURL *url = [NSURL URLWithString:@"http://zacandcatie.com/YouTube/json.php"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLConnection *con = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[con start];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
data = [[NSMutableData alloc]init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData
{
[data appendData:theData];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
news = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
for (int i =0; i < [news count]; i++)
{
NSIndexPath *indexPath = [self.mainTable indexPathForSelectedRow];
title =[[news objectAtIndex:indexPath.row+i]objectForKey:@"title"];
if (!all) {
all = [NSMutableArray array];
}
[all addObject:title];
}
NSLog(@"%@",all);
[mainTable reloadData];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:@"Error" message:@"The Connection has been LOST" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[errorView show];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
你是我的 json 网址。我想在 sqlite 中存储“title”和“date_string”值。 请指导我!!!
【问题讨论】:
-
你可以用字典代替sqlite db
-
好的,我知道,但我不知道我在做什么?
-
我不知道如何在sqlite的表中存储字典!!!
-
这里回答了“[我们如何将数据存储到 NSDictionary?][1]”[1] 的问题:stackoverflow.com/questions/1760371/…
-
我的朋友我的问题是我不了解 sqlite 数据库并将数据存储在其中(不是存储字典)请指导我如何在 sqlite 中存储 nsdictionary
标签: ios objective-c json sqlite