0
我是新國展局在iPhone application.I要實現JSON parsing.I已經嘗試了設在net.But,樣品不能找出如何得到確切的方法在做json解析的時候url的索引值。任何人都可以在早期完成。作爲初學者,任何人都可以引導我。錯誤在iPhone應用程序解析JSON的URL
提前 iPhone開發
我是新國展局在iPhone application.I要實現JSON parsing.I已經嘗試了設在net.But,樣品不能找出如何得到確切的方法在做json解析的時候url的索引值。任何人都可以在早期完成。作爲初學者,任何人都可以引導我。錯誤在iPhone應用程序解析JSON的URL
提前 iPhone開發
等待的積極響應
感謝您的觀點didload
NSURLRequest *request = [NSURLRequest requestWithURL:
[NSURL URLWithString:Str_URL]];
// NSLog(@"\n\n\n request ===%@\n\n\n",request);
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
responseData = [[NSMutableData data] init];
} else {
// Inform the user that the connection failed.
}
#pragma mark NSURLConnection Delegate methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
//NSLog(@"\n\n\n response ===%@\n\n\n",response);
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
//NSLog(@"\n\n\n data ===%@\n\n\n",data);
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSString *strerror = [NSString stringWithFormat:@"Connection failed: %@", [error description]];
NSLog(@"\n\n\n error ===%@\n\n\n",strerror);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
if(responseData != nil)
{
NSError *error = nil;
id result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
}
}
試試這個
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[responseData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[responseData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
[connection release];
responseData = nil;
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
responseData = nil;
NSLog(@"response String= %@",responseString);
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *data = (NSDictionary *) [parser objectWithString:responseString error:nil];
NSDictionary *menu = (NSDictionary *) [data objectForKey:@"MainTag"];
NSString *com=(NSString *) [menu objectForKey:@"yourSubTag"];
}
添加JSON和這裏的代碼 –
[你有什麼想法](http://wwwww.whathavey outried.com)這裏 – akk
發佈您的代碼@alex ..我也跟着下面的網址,試圖.....教學貫徹HTTP://mobiledevelopertips.com/networking/iphone-json-flickr-tutorial-part-2。 HTML .....主要問題,我在哪裏打是如何獲得JSON陣列響應,並得到第一個數組的索引值....等待的積極響應 – Preet