我们如何将视频添加到tableview?

时间:2014-06-19 09:23:15

标签: ios

在我的应用中,我想在后续的tableview行中显示视频。视频将以JSON服务提取,该服务以字符串格式提供。我们怎样才能做到这一点。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

如果您想使用GET从服务器获取响应(VIDEO),您可以尝试以下方法

 //just give your URL instead of my URL

   NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL              URLWithString:@"http://api.worldweatheronline.com/free/v1/search.ashx?query=London&num_of_results=3&format=json&key=xkq544hkar4m69qujdgujn7w"]];

  [request setHTTPMethod:@"GET"];

  [request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"content-type"];

  NSError *err;

  NSURLResponse *response;

  NSData *responseData = [NSURLConnection sendSynchronousRequest:request   returningResponse:&response error:&err];

 //You need to check response.Once you get the response copy that and paste in ONLINE  JSON VIEWER.If you do this clearly you can get the correct results.    

 //After that it depends upon the json format whether it is DICTIONARY or ARRAY 

        //If it is Dictionary
   NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error: &err];
              or
        //If it is Array
   NSMutableArray *json=[NSJSONSerialization JSONObjectWithData:responseData  options:kNilOptions error:nil];

   NSMutableArray *imgvd=[[NSMutableArray alloc]init];

   for (int i =0 ; i<json.count; i++) 
   {

        NSString *dd =[[json objectAtIndex:i]objectForKey:@"url"];
        NSString *pp = [[json objectAtIndex:i]objectForKey:@"title"];
        vedios *myvd = [[vedios alloc]initWithvideo:dd andtitle:pp];
        [imgvd addObject:myvd];
   }