How To do json type Response?












0















I have one collection view in that I have to show images and video coming from backend I'm very new to do this I'm getting this response from backend.



SliderList =     (
{
SliderID = 1;
SliderType = 1;
SliderURL = "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup2.png";
Status = 1;
},
{
SliderID = 2;
SliderType = 1;
SliderURL = "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup3.png";
Status = 1;
},
{
SliderID = 3;
SliderType = 2;
SliderURL = "https://www.youtube.com/watch?v=l1yN0KUHgoc";
Status = 1;
}
);
}


and I did like this



 NSMutableDictionary *sampleDict = [ImagesArray objectAtIndex:indexPath.row];
NSString *imageStr = [[NSString alloc]init];
imageStr = [sampleDict valueForKey:@"SliderURL"];

if([imageStr isEqualToString:@"1"] || imageStr == nil)
{
cell.addImageView.image = [UIImage imageNamed:@""];
}
else
{
[cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
placeholderImage:[UIImage imageNamed:@"default"]];`
}


for above only images coming. if any Answer it would be appreciated. Thanks in Advance.










share|improve this question

























  • plz add additional code

    – Anbu.Karthik
    Nov 21 '18 at 7:22











  • if(requestType == RequestTypeHomeSlider) { NSLog(@"%@",responseObject); NSString *respCode =[NSString stringWithFormat:@"%@", [responseDict valueForKey:@"StatusCode"]]; if([respCode isEqualToString:@"200"]) { ImagesArray= [NSMutableArray new]; ImagesArray = [responseObject valueForKey:@"SliderList"]; [_imageCollectionView reloadData]; }

    – santoshi
    Nov 21 '18 at 7:25











  • plz add additional code

    – Anbu.Karthik
    Nov 21 '18 at 7:26











  • Hi @karthik which code you want? please tell me

    – santoshi
    Nov 21 '18 at 7:27











  • related to your collectionview code or add entire class code in your question

    – Anbu.Karthik
    Nov 21 '18 at 7:28


















0















I have one collection view in that I have to show images and video coming from backend I'm very new to do this I'm getting this response from backend.



SliderList =     (
{
SliderID = 1;
SliderType = 1;
SliderURL = "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup2.png";
Status = 1;
},
{
SliderID = 2;
SliderType = 1;
SliderURL = "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup3.png";
Status = 1;
},
{
SliderID = 3;
SliderType = 2;
SliderURL = "https://www.youtube.com/watch?v=l1yN0KUHgoc";
Status = 1;
}
);
}


and I did like this



 NSMutableDictionary *sampleDict = [ImagesArray objectAtIndex:indexPath.row];
NSString *imageStr = [[NSString alloc]init];
imageStr = [sampleDict valueForKey:@"SliderURL"];

if([imageStr isEqualToString:@"1"] || imageStr == nil)
{
cell.addImageView.image = [UIImage imageNamed:@""];
}
else
{
[cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
placeholderImage:[UIImage imageNamed:@"default"]];`
}


for above only images coming. if any Answer it would be appreciated. Thanks in Advance.










share|improve this question

























  • plz add additional code

    – Anbu.Karthik
    Nov 21 '18 at 7:22











  • if(requestType == RequestTypeHomeSlider) { NSLog(@"%@",responseObject); NSString *respCode =[NSString stringWithFormat:@"%@", [responseDict valueForKey:@"StatusCode"]]; if([respCode isEqualToString:@"200"]) { ImagesArray= [NSMutableArray new]; ImagesArray = [responseObject valueForKey:@"SliderList"]; [_imageCollectionView reloadData]; }

    – santoshi
    Nov 21 '18 at 7:25











  • plz add additional code

    – Anbu.Karthik
    Nov 21 '18 at 7:26











  • Hi @karthik which code you want? please tell me

    – santoshi
    Nov 21 '18 at 7:27











  • related to your collectionview code or add entire class code in your question

    – Anbu.Karthik
    Nov 21 '18 at 7:28
















0












0








0


2






I have one collection view in that I have to show images and video coming from backend I'm very new to do this I'm getting this response from backend.



SliderList =     (
{
SliderID = 1;
SliderType = 1;
SliderURL = "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup2.png";
Status = 1;
},
{
SliderID = 2;
SliderType = 1;
SliderURL = "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup3.png";
Status = 1;
},
{
SliderID = 3;
SliderType = 2;
SliderURL = "https://www.youtube.com/watch?v=l1yN0KUHgoc";
Status = 1;
}
);
}


and I did like this



 NSMutableDictionary *sampleDict = [ImagesArray objectAtIndex:indexPath.row];
NSString *imageStr = [[NSString alloc]init];
imageStr = [sampleDict valueForKey:@"SliderURL"];

if([imageStr isEqualToString:@"1"] || imageStr == nil)
{
cell.addImageView.image = [UIImage imageNamed:@""];
}
else
{
[cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
placeholderImage:[UIImage imageNamed:@"default"]];`
}


for above only images coming. if any Answer it would be appreciated. Thanks in Advance.










share|improve this question
















I have one collection view in that I have to show images and video coming from backend I'm very new to do this I'm getting this response from backend.



SliderList =     (
{
SliderID = 1;
SliderType = 1;
SliderURL = "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup2.png";
Status = 1;
},
{
SliderID = 2;
SliderType = 1;
SliderURL = "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup3.png";
Status = 1;
},
{
SliderID = 3;
SliderType = 2;
SliderURL = "https://www.youtube.com/watch?v=l1yN0KUHgoc";
Status = 1;
}
);
}


and I did like this



 NSMutableDictionary *sampleDict = [ImagesArray objectAtIndex:indexPath.row];
NSString *imageStr = [[NSString alloc]init];
imageStr = [sampleDict valueForKey:@"SliderURL"];

if([imageStr isEqualToString:@"1"] || imageStr == nil)
{
cell.addImageView.image = [UIImage imageNamed:@""];
}
else
{
[cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
placeholderImage:[UIImage imageNamed:@"default"]];`
}


for above only images coming. if any Answer it would be appreciated. Thanks in Advance.







ios objective-c image video uicollectionview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 7:21









Anbu.Karthik

61.5k16121111




61.5k16121111










asked Nov 21 '18 at 7:19









santoshisantoshi

324113




324113













  • plz add additional code

    – Anbu.Karthik
    Nov 21 '18 at 7:22











  • if(requestType == RequestTypeHomeSlider) { NSLog(@"%@",responseObject); NSString *respCode =[NSString stringWithFormat:@"%@", [responseDict valueForKey:@"StatusCode"]]; if([respCode isEqualToString:@"200"]) { ImagesArray= [NSMutableArray new]; ImagesArray = [responseObject valueForKey:@"SliderList"]; [_imageCollectionView reloadData]; }

    – santoshi
    Nov 21 '18 at 7:25











  • plz add additional code

    – Anbu.Karthik
    Nov 21 '18 at 7:26











  • Hi @karthik which code you want? please tell me

    – santoshi
    Nov 21 '18 at 7:27











  • related to your collectionview code or add entire class code in your question

    – Anbu.Karthik
    Nov 21 '18 at 7:28





















  • plz add additional code

    – Anbu.Karthik
    Nov 21 '18 at 7:22











  • if(requestType == RequestTypeHomeSlider) { NSLog(@"%@",responseObject); NSString *respCode =[NSString stringWithFormat:@"%@", [responseDict valueForKey:@"StatusCode"]]; if([respCode isEqualToString:@"200"]) { ImagesArray= [NSMutableArray new]; ImagesArray = [responseObject valueForKey:@"SliderList"]; [_imageCollectionView reloadData]; }

    – santoshi
    Nov 21 '18 at 7:25











  • plz add additional code

    – Anbu.Karthik
    Nov 21 '18 at 7:26











  • Hi @karthik which code you want? please tell me

    – santoshi
    Nov 21 '18 at 7:27











  • related to your collectionview code or add entire class code in your question

    – Anbu.Karthik
    Nov 21 '18 at 7:28



















plz add additional code

– Anbu.Karthik
Nov 21 '18 at 7:22





plz add additional code

– Anbu.Karthik
Nov 21 '18 at 7:22













if(requestType == RequestTypeHomeSlider) { NSLog(@"%@",responseObject); NSString *respCode =[NSString stringWithFormat:@"%@", [responseDict valueForKey:@"StatusCode"]]; if([respCode isEqualToString:@"200"]) { ImagesArray= [NSMutableArray new]; ImagesArray = [responseObject valueForKey:@"SliderList"]; [_imageCollectionView reloadData]; }

– santoshi
Nov 21 '18 at 7:25





if(requestType == RequestTypeHomeSlider) { NSLog(@"%@",responseObject); NSString *respCode =[NSString stringWithFormat:@"%@", [responseDict valueForKey:@"StatusCode"]]; if([respCode isEqualToString:@"200"]) { ImagesArray= [NSMutableArray new]; ImagesArray = [responseObject valueForKey:@"SliderList"]; [_imageCollectionView reloadData]; }

– santoshi
Nov 21 '18 at 7:25













plz add additional code

– Anbu.Karthik
Nov 21 '18 at 7:26





plz add additional code

– Anbu.Karthik
Nov 21 '18 at 7:26













Hi @karthik which code you want? please tell me

– santoshi
Nov 21 '18 at 7:27





Hi @karthik which code you want? please tell me

– santoshi
Nov 21 '18 at 7:27













related to your collectionview code or add entire class code in your question

– Anbu.Karthik
Nov 21 '18 at 7:28







related to your collectionview code or add entire class code in your question

– Anbu.Karthik
Nov 21 '18 at 7:28














3 Answers
3






active

oldest

votes


















1














I got Answer for my question thank you every one who responded to me



 if ([ImagesArray[indexPath.row][@"SliderType"] intValue]==1) {

NSString *imageStr=ImagesArray[indexPath.row][@"SliderURL"];

[cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
placeholderImage:[UIImage imageNamed:@"default"]];

}else if ([ImagesArray[indexPath.row][@"SliderType"] intValue]==2) {

NSString *imageStr=ImagesArray[indexPath.row][@"SliderURL"];
[cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
placeholderImage:[UIImage imageNamed:@"VideoButton"]];

}





share|improve this answer































    0














    As I understand from question and your extended discussion on chat you are facing trouble with showing video in cell along with Images. In order to show video along with image you will need to use a different approach.




    • First thing you need to do is to find if this is video URL or image. Best way to do that will be to segregate that by adding a parameter in your web-service which indicate if this is a image or video.

    • Once that is out of system you will need a special view that can load video perfectly i have used this library and it works fine.

    • Now in your cell add both imageView and video player view, and add a condition where you check if it's video then display YTPlayerView or imageView based on returned information.


    Then with help pf these function you can load video on your player View:



    + (NSString *)extractYoutubeIdFromLink:(NSString *)link {
    if (link == nil) nil;

    NSString *regexString = @"((?<=(v|V)/)|(?<=be/)|(?<=(\?|\&)v=)|(?<=embed/))([\w-]++)";
    NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:regexString
    options:NSRegularExpressionCaseInsensitive
    error:nil];

    NSArray *array = [regExp matchesInString:link options:0 range:NSMakeRange(0,link.length)];
    if (array.count > 0) {
    NSTextCheckingResult *result = array.firstObject;
    return [link substringWithRange:result.range];
    }
    return nil;
    }


    //Write this line on your function where you want to load video
    [_videoView loadWithVideoId:[SCUtility extractYoutubeIdFromLink:_videoURL]];





    share|improve this answer































      0














      I have added code in swift lang .. You can take reference and apply same logic there. It will work



         let ImagesArray =     [
      [
      "SliderID" : 1,
      "SliderType" : 1,
      "SliderURL" : "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup2.png",
      "Status" : 1
      ],
      [
      "SliderID" : 2,
      "SliderType" : 1,
      "SliderURL" : "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup3.png",
      "Status" : 1
      ],
      [
      "SliderID" : 3,
      "SliderType" : 2,
      "SliderURL" : "https://www.youtube.com/watch?v=l1yN0KUHgoc",
      "Status" : 1
      ]
      ]


      In tableview cellforrow u can implement like this :



          let sampleDict = ImagesArray[indexPath.row] as? NSDictionary
      let SliderURL = sampleDict.valueForkey("SliderURL") as? String
      let SliderType = sampleDict.objectForkey("SliderType") as? NSNumber

      if SliderURL != nil{
      //means url abvl
      if SliderType == 2{
      //video data
      cell.addImageView.image = "set video default thumbnail image "

      }else if SliderType == 1{
      //imagedata
      // cell.addImageView.image = "set ur image "
      }
      }


      In Objective C



          NSMutableDictionary *sampleDict = [ImagesArray objectAtIndex:indexPath.row];
      NSString *imageStr = [[NSString alloc]init];
      imageStr = [sampleDict valueForKey:@"SliderURL"];


      // NSString * SliderType = [[NSString alloc]init];
      // SliderType = [sampleDict valueForKey:@"SliderType"];



       int SliderType = [[sampleDict valueForKey:@"SliderType"] integerValue];
      NSLog(@"%i", SliderType);

      if(imageStr != nil)
      {

      //if([SliderType isEqualToString:@"2"]
      if [SliderType isEqualToNumber:[NSNumber numberWithInt:2]] {

      cell.addImageView.image = [UIImage imageNamed:@"default"];

      }else if [SliderType isEqualToNumber:[NSNumber numberWithInt:1]] {

      [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
      placeholderImage:[UIImage imageNamed:@"default"]];`
      }else{
      //nothng
      }
      }
      else
      {
      //SliderURL is nil
      }





      share|improve this answer


























      • can you please update in objective c

        – santoshi
        Nov 21 '18 at 9:47











      • code edited apply it .. @santoshi

        – PRADIP KUMAR
        Nov 21 '18 at 9:57











      • error coming invalid argument NCSFNUMBEr

        – santoshi
        Nov 21 '18 at 10:37











      • your SliderType data is of number type.. first fetch in number/Int type

        – PRADIP KUMAR
        Nov 21 '18 at 11:17













      • int SliderType = [sampleDict[@"SliderType"] integerValue];

        – PRADIP KUMAR
        Nov 21 '18 at 11:20











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407029%2fhow-to-do-json-type-response%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      I got Answer for my question thank you every one who responded to me



       if ([ImagesArray[indexPath.row][@"SliderType"] intValue]==1) {

      NSString *imageStr=ImagesArray[indexPath.row][@"SliderURL"];

      [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
      placeholderImage:[UIImage imageNamed:@"default"]];

      }else if ([ImagesArray[indexPath.row][@"SliderType"] intValue]==2) {

      NSString *imageStr=ImagesArray[indexPath.row][@"SliderURL"];
      [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
      placeholderImage:[UIImage imageNamed:@"VideoButton"]];

      }





      share|improve this answer




























        1














        I got Answer for my question thank you every one who responded to me



         if ([ImagesArray[indexPath.row][@"SliderType"] intValue]==1) {

        NSString *imageStr=ImagesArray[indexPath.row][@"SliderURL"];

        [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
        placeholderImage:[UIImage imageNamed:@"default"]];

        }else if ([ImagesArray[indexPath.row][@"SliderType"] intValue]==2) {

        NSString *imageStr=ImagesArray[indexPath.row][@"SliderURL"];
        [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
        placeholderImage:[UIImage imageNamed:@"VideoButton"]];

        }





        share|improve this answer


























          1












          1








          1







          I got Answer for my question thank you every one who responded to me



           if ([ImagesArray[indexPath.row][@"SliderType"] intValue]==1) {

          NSString *imageStr=ImagesArray[indexPath.row][@"SliderURL"];

          [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
          placeholderImage:[UIImage imageNamed:@"default"]];

          }else if ([ImagesArray[indexPath.row][@"SliderType"] intValue]==2) {

          NSString *imageStr=ImagesArray[indexPath.row][@"SliderURL"];
          [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
          placeholderImage:[UIImage imageNamed:@"VideoButton"]];

          }





          share|improve this answer













          I got Answer for my question thank you every one who responded to me



           if ([ImagesArray[indexPath.row][@"SliderType"] intValue]==1) {

          NSString *imageStr=ImagesArray[indexPath.row][@"SliderURL"];

          [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
          placeholderImage:[UIImage imageNamed:@"default"]];

          }else if ([ImagesArray[indexPath.row][@"SliderType"] intValue]==2) {

          NSString *imageStr=ImagesArray[indexPath.row][@"SliderURL"];
          [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
          placeholderImage:[UIImage imageNamed:@"VideoButton"]];

          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 12:34









          santoshisantoshi

          324113




          324113

























              0














              As I understand from question and your extended discussion on chat you are facing trouble with showing video in cell along with Images. In order to show video along with image you will need to use a different approach.




              • First thing you need to do is to find if this is video URL or image. Best way to do that will be to segregate that by adding a parameter in your web-service which indicate if this is a image or video.

              • Once that is out of system you will need a special view that can load video perfectly i have used this library and it works fine.

              • Now in your cell add both imageView and video player view, and add a condition where you check if it's video then display YTPlayerView or imageView based on returned information.


              Then with help pf these function you can load video on your player View:



              + (NSString *)extractYoutubeIdFromLink:(NSString *)link {
              if (link == nil) nil;

              NSString *regexString = @"((?<=(v|V)/)|(?<=be/)|(?<=(\?|\&)v=)|(?<=embed/))([\w-]++)";
              NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:regexString
              options:NSRegularExpressionCaseInsensitive
              error:nil];

              NSArray *array = [regExp matchesInString:link options:0 range:NSMakeRange(0,link.length)];
              if (array.count > 0) {
              NSTextCheckingResult *result = array.firstObject;
              return [link substringWithRange:result.range];
              }
              return nil;
              }


              //Write this line on your function where you want to load video
              [_videoView loadWithVideoId:[SCUtility extractYoutubeIdFromLink:_videoURL]];





              share|improve this answer




























                0














                As I understand from question and your extended discussion on chat you are facing trouble with showing video in cell along with Images. In order to show video along with image you will need to use a different approach.




                • First thing you need to do is to find if this is video URL or image. Best way to do that will be to segregate that by adding a parameter in your web-service which indicate if this is a image or video.

                • Once that is out of system you will need a special view that can load video perfectly i have used this library and it works fine.

                • Now in your cell add both imageView and video player view, and add a condition where you check if it's video then display YTPlayerView or imageView based on returned information.


                Then with help pf these function you can load video on your player View:



                + (NSString *)extractYoutubeIdFromLink:(NSString *)link {
                if (link == nil) nil;

                NSString *regexString = @"((?<=(v|V)/)|(?<=be/)|(?<=(\?|\&)v=)|(?<=embed/))([\w-]++)";
                NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:regexString
                options:NSRegularExpressionCaseInsensitive
                error:nil];

                NSArray *array = [regExp matchesInString:link options:0 range:NSMakeRange(0,link.length)];
                if (array.count > 0) {
                NSTextCheckingResult *result = array.firstObject;
                return [link substringWithRange:result.range];
                }
                return nil;
                }


                //Write this line on your function where you want to load video
                [_videoView loadWithVideoId:[SCUtility extractYoutubeIdFromLink:_videoURL]];





                share|improve this answer


























                  0












                  0








                  0







                  As I understand from question and your extended discussion on chat you are facing trouble with showing video in cell along with Images. In order to show video along with image you will need to use a different approach.




                  • First thing you need to do is to find if this is video URL or image. Best way to do that will be to segregate that by adding a parameter in your web-service which indicate if this is a image or video.

                  • Once that is out of system you will need a special view that can load video perfectly i have used this library and it works fine.

                  • Now in your cell add both imageView and video player view, and add a condition where you check if it's video then display YTPlayerView or imageView based on returned information.


                  Then with help pf these function you can load video on your player View:



                  + (NSString *)extractYoutubeIdFromLink:(NSString *)link {
                  if (link == nil) nil;

                  NSString *regexString = @"((?<=(v|V)/)|(?<=be/)|(?<=(\?|\&)v=)|(?<=embed/))([\w-]++)";
                  NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:regexString
                  options:NSRegularExpressionCaseInsensitive
                  error:nil];

                  NSArray *array = [regExp matchesInString:link options:0 range:NSMakeRange(0,link.length)];
                  if (array.count > 0) {
                  NSTextCheckingResult *result = array.firstObject;
                  return [link substringWithRange:result.range];
                  }
                  return nil;
                  }


                  //Write this line on your function where you want to load video
                  [_videoView loadWithVideoId:[SCUtility extractYoutubeIdFromLink:_videoURL]];





                  share|improve this answer













                  As I understand from question and your extended discussion on chat you are facing trouble with showing video in cell along with Images. In order to show video along with image you will need to use a different approach.




                  • First thing you need to do is to find if this is video URL or image. Best way to do that will be to segregate that by adding a parameter in your web-service which indicate if this is a image or video.

                  • Once that is out of system you will need a special view that can load video perfectly i have used this library and it works fine.

                  • Now in your cell add both imageView and video player view, and add a condition where you check if it's video then display YTPlayerView or imageView based on returned information.


                  Then with help pf these function you can load video on your player View:



                  + (NSString *)extractYoutubeIdFromLink:(NSString *)link {
                  if (link == nil) nil;

                  NSString *regexString = @"((?<=(v|V)/)|(?<=be/)|(?<=(\?|\&)v=)|(?<=embed/))([\w-]++)";
                  NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:regexString
                  options:NSRegularExpressionCaseInsensitive
                  error:nil];

                  NSArray *array = [regExp matchesInString:link options:0 range:NSMakeRange(0,link.length)];
                  if (array.count > 0) {
                  NSTextCheckingResult *result = array.firstObject;
                  return [link substringWithRange:result.range];
                  }
                  return nil;
                  }


                  //Write this line on your function where you want to load video
                  [_videoView loadWithVideoId:[SCUtility extractYoutubeIdFromLink:_videoURL]];






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 8:01









                  rptwsthirptwsthi

                  8,56885392




                  8,56885392























                      0














                      I have added code in swift lang .. You can take reference and apply same logic there. It will work



                         let ImagesArray =     [
                      [
                      "SliderID" : 1,
                      "SliderType" : 1,
                      "SliderURL" : "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup2.png",
                      "Status" : 1
                      ],
                      [
                      "SliderID" : 2,
                      "SliderType" : 1,
                      "SliderURL" : "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup3.png",
                      "Status" : 1
                      ],
                      [
                      "SliderID" : 3,
                      "SliderType" : 2,
                      "SliderURL" : "https://www.youtube.com/watch?v=l1yN0KUHgoc",
                      "Status" : 1
                      ]
                      ]


                      In tableview cellforrow u can implement like this :



                          let sampleDict = ImagesArray[indexPath.row] as? NSDictionary
                      let SliderURL = sampleDict.valueForkey("SliderURL") as? String
                      let SliderType = sampleDict.objectForkey("SliderType") as? NSNumber

                      if SliderURL != nil{
                      //means url abvl
                      if SliderType == 2{
                      //video data
                      cell.addImageView.image = "set video default thumbnail image "

                      }else if SliderType == 1{
                      //imagedata
                      // cell.addImageView.image = "set ur image "
                      }
                      }


                      In Objective C



                          NSMutableDictionary *sampleDict = [ImagesArray objectAtIndex:indexPath.row];
                      NSString *imageStr = [[NSString alloc]init];
                      imageStr = [sampleDict valueForKey:@"SliderURL"];


                      // NSString * SliderType = [[NSString alloc]init];
                      // SliderType = [sampleDict valueForKey:@"SliderType"];



                       int SliderType = [[sampleDict valueForKey:@"SliderType"] integerValue];
                      NSLog(@"%i", SliderType);

                      if(imageStr != nil)
                      {

                      //if([SliderType isEqualToString:@"2"]
                      if [SliderType isEqualToNumber:[NSNumber numberWithInt:2]] {

                      cell.addImageView.image = [UIImage imageNamed:@"default"];

                      }else if [SliderType isEqualToNumber:[NSNumber numberWithInt:1]] {

                      [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
                      placeholderImage:[UIImage imageNamed:@"default"]];`
                      }else{
                      //nothng
                      }
                      }
                      else
                      {
                      //SliderURL is nil
                      }





                      share|improve this answer


























                      • can you please update in objective c

                        – santoshi
                        Nov 21 '18 at 9:47











                      • code edited apply it .. @santoshi

                        – PRADIP KUMAR
                        Nov 21 '18 at 9:57











                      • error coming invalid argument NCSFNUMBEr

                        – santoshi
                        Nov 21 '18 at 10:37











                      • your SliderType data is of number type.. first fetch in number/Int type

                        – PRADIP KUMAR
                        Nov 21 '18 at 11:17













                      • int SliderType = [sampleDict[@"SliderType"] integerValue];

                        – PRADIP KUMAR
                        Nov 21 '18 at 11:20
















                      0














                      I have added code in swift lang .. You can take reference and apply same logic there. It will work



                         let ImagesArray =     [
                      [
                      "SliderID" : 1,
                      "SliderType" : 1,
                      "SliderURL" : "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup2.png",
                      "Status" : 1
                      ],
                      [
                      "SliderID" : 2,
                      "SliderType" : 1,
                      "SliderURL" : "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup3.png",
                      "Status" : 1
                      ],
                      [
                      "SliderID" : 3,
                      "SliderType" : 2,
                      "SliderURL" : "https://www.youtube.com/watch?v=l1yN0KUHgoc",
                      "Status" : 1
                      ]
                      ]


                      In tableview cellforrow u can implement like this :



                          let sampleDict = ImagesArray[indexPath.row] as? NSDictionary
                      let SliderURL = sampleDict.valueForkey("SliderURL") as? String
                      let SliderType = sampleDict.objectForkey("SliderType") as? NSNumber

                      if SliderURL != nil{
                      //means url abvl
                      if SliderType == 2{
                      //video data
                      cell.addImageView.image = "set video default thumbnail image "

                      }else if SliderType == 1{
                      //imagedata
                      // cell.addImageView.image = "set ur image "
                      }
                      }


                      In Objective C



                          NSMutableDictionary *sampleDict = [ImagesArray objectAtIndex:indexPath.row];
                      NSString *imageStr = [[NSString alloc]init];
                      imageStr = [sampleDict valueForKey:@"SliderURL"];


                      // NSString * SliderType = [[NSString alloc]init];
                      // SliderType = [sampleDict valueForKey:@"SliderType"];



                       int SliderType = [[sampleDict valueForKey:@"SliderType"] integerValue];
                      NSLog(@"%i", SliderType);

                      if(imageStr != nil)
                      {

                      //if([SliderType isEqualToString:@"2"]
                      if [SliderType isEqualToNumber:[NSNumber numberWithInt:2]] {

                      cell.addImageView.image = [UIImage imageNamed:@"default"];

                      }else if [SliderType isEqualToNumber:[NSNumber numberWithInt:1]] {

                      [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
                      placeholderImage:[UIImage imageNamed:@"default"]];`
                      }else{
                      //nothng
                      }
                      }
                      else
                      {
                      //SliderURL is nil
                      }





                      share|improve this answer


























                      • can you please update in objective c

                        – santoshi
                        Nov 21 '18 at 9:47











                      • code edited apply it .. @santoshi

                        – PRADIP KUMAR
                        Nov 21 '18 at 9:57











                      • error coming invalid argument NCSFNUMBEr

                        – santoshi
                        Nov 21 '18 at 10:37











                      • your SliderType data is of number type.. first fetch in number/Int type

                        – PRADIP KUMAR
                        Nov 21 '18 at 11:17













                      • int SliderType = [sampleDict[@"SliderType"] integerValue];

                        – PRADIP KUMAR
                        Nov 21 '18 at 11:20














                      0












                      0








                      0







                      I have added code in swift lang .. You can take reference and apply same logic there. It will work



                         let ImagesArray =     [
                      [
                      "SliderID" : 1,
                      "SliderType" : 1,
                      "SliderURL" : "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup2.png",
                      "Status" : 1
                      ],
                      [
                      "SliderID" : 2,
                      "SliderType" : 1,
                      "SliderURL" : "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup3.png",
                      "Status" : 1
                      ],
                      [
                      "SliderID" : 3,
                      "SliderType" : 2,
                      "SliderURL" : "https://www.youtube.com/watch?v=l1yN0KUHgoc",
                      "Status" : 1
                      ]
                      ]


                      In tableview cellforrow u can implement like this :



                          let sampleDict = ImagesArray[indexPath.row] as? NSDictionary
                      let SliderURL = sampleDict.valueForkey("SliderURL") as? String
                      let SliderType = sampleDict.objectForkey("SliderType") as? NSNumber

                      if SliderURL != nil{
                      //means url abvl
                      if SliderType == 2{
                      //video data
                      cell.addImageView.image = "set video default thumbnail image "

                      }else if SliderType == 1{
                      //imagedata
                      // cell.addImageView.image = "set ur image "
                      }
                      }


                      In Objective C



                          NSMutableDictionary *sampleDict = [ImagesArray objectAtIndex:indexPath.row];
                      NSString *imageStr = [[NSString alloc]init];
                      imageStr = [sampleDict valueForKey:@"SliderURL"];


                      // NSString * SliderType = [[NSString alloc]init];
                      // SliderType = [sampleDict valueForKey:@"SliderType"];



                       int SliderType = [[sampleDict valueForKey:@"SliderType"] integerValue];
                      NSLog(@"%i", SliderType);

                      if(imageStr != nil)
                      {

                      //if([SliderType isEqualToString:@"2"]
                      if [SliderType isEqualToNumber:[NSNumber numberWithInt:2]] {

                      cell.addImageView.image = [UIImage imageNamed:@"default"];

                      }else if [SliderType isEqualToNumber:[NSNumber numberWithInt:1]] {

                      [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
                      placeholderImage:[UIImage imageNamed:@"default"]];`
                      }else{
                      //nothng
                      }
                      }
                      else
                      {
                      //SliderURL is nil
                      }





                      share|improve this answer















                      I have added code in swift lang .. You can take reference and apply same logic there. It will work



                         let ImagesArray =     [
                      [
                      "SliderID" : 1,
                      "SliderType" : 1,
                      "SliderURL" : "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup2.png",
                      "Status" : 1
                      ],
                      [
                      "SliderID" : 2,
                      "SliderType" : 1,
                      "SliderURL" : "http://mca.bananaappscenter.com/Images/SliderImages/MaskGroup3.png",
                      "Status" : 1
                      ],
                      [
                      "SliderID" : 3,
                      "SliderType" : 2,
                      "SliderURL" : "https://www.youtube.com/watch?v=l1yN0KUHgoc",
                      "Status" : 1
                      ]
                      ]


                      In tableview cellforrow u can implement like this :



                          let sampleDict = ImagesArray[indexPath.row] as? NSDictionary
                      let SliderURL = sampleDict.valueForkey("SliderURL") as? String
                      let SliderType = sampleDict.objectForkey("SliderType") as? NSNumber

                      if SliderURL != nil{
                      //means url abvl
                      if SliderType == 2{
                      //video data
                      cell.addImageView.image = "set video default thumbnail image "

                      }else if SliderType == 1{
                      //imagedata
                      // cell.addImageView.image = "set ur image "
                      }
                      }


                      In Objective C



                          NSMutableDictionary *sampleDict = [ImagesArray objectAtIndex:indexPath.row];
                      NSString *imageStr = [[NSString alloc]init];
                      imageStr = [sampleDict valueForKey:@"SliderURL"];


                      // NSString * SliderType = [[NSString alloc]init];
                      // SliderType = [sampleDict valueForKey:@"SliderType"];



                       int SliderType = [[sampleDict valueForKey:@"SliderType"] integerValue];
                      NSLog(@"%i", SliderType);

                      if(imageStr != nil)
                      {

                      //if([SliderType isEqualToString:@"2"]
                      if [SliderType isEqualToNumber:[NSNumber numberWithInt:2]] {

                      cell.addImageView.image = [UIImage imageNamed:@"default"];

                      }else if [SliderType isEqualToNumber:[NSNumber numberWithInt:1]] {

                      [cell.addImageView sd_setImageWithURL:[NSURL URLWithString:imageStr]
                      placeholderImage:[UIImage imageNamed:@"default"]];`
                      }else{
                      //nothng
                      }
                      }
                      else
                      {
                      //SliderURL is nil
                      }






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 21 '18 at 11:25

























                      answered Nov 21 '18 at 9:44









                      PRADIP KUMARPRADIP KUMAR

                      2291424




                      2291424













                      • can you please update in objective c

                        – santoshi
                        Nov 21 '18 at 9:47











                      • code edited apply it .. @santoshi

                        – PRADIP KUMAR
                        Nov 21 '18 at 9:57











                      • error coming invalid argument NCSFNUMBEr

                        – santoshi
                        Nov 21 '18 at 10:37











                      • your SliderType data is of number type.. first fetch in number/Int type

                        – PRADIP KUMAR
                        Nov 21 '18 at 11:17













                      • int SliderType = [sampleDict[@"SliderType"] integerValue];

                        – PRADIP KUMAR
                        Nov 21 '18 at 11:20



















                      • can you please update in objective c

                        – santoshi
                        Nov 21 '18 at 9:47











                      • code edited apply it .. @santoshi

                        – PRADIP KUMAR
                        Nov 21 '18 at 9:57











                      • error coming invalid argument NCSFNUMBEr

                        – santoshi
                        Nov 21 '18 at 10:37











                      • your SliderType data is of number type.. first fetch in number/Int type

                        – PRADIP KUMAR
                        Nov 21 '18 at 11:17













                      • int SliderType = [sampleDict[@"SliderType"] integerValue];

                        – PRADIP KUMAR
                        Nov 21 '18 at 11:20

















                      can you please update in objective c

                      – santoshi
                      Nov 21 '18 at 9:47





                      can you please update in objective c

                      – santoshi
                      Nov 21 '18 at 9:47













                      code edited apply it .. @santoshi

                      – PRADIP KUMAR
                      Nov 21 '18 at 9:57





                      code edited apply it .. @santoshi

                      – PRADIP KUMAR
                      Nov 21 '18 at 9:57













                      error coming invalid argument NCSFNUMBEr

                      – santoshi
                      Nov 21 '18 at 10:37





                      error coming invalid argument NCSFNUMBEr

                      – santoshi
                      Nov 21 '18 at 10:37













                      your SliderType data is of number type.. first fetch in number/Int type

                      – PRADIP KUMAR
                      Nov 21 '18 at 11:17







                      your SliderType data is of number type.. first fetch in number/Int type

                      – PRADIP KUMAR
                      Nov 21 '18 at 11:17















                      int SliderType = [sampleDict[@"SliderType"] integerValue];

                      – PRADIP KUMAR
                      Nov 21 '18 at 11:20





                      int SliderType = [sampleDict[@"SliderType"] integerValue];

                      – PRADIP KUMAR
                      Nov 21 '18 at 11:20


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407029%2fhow-to-do-json-type-response%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

                      ts Property 'filter' does not exist on type '{}'

                      Notepad++ export/extract a list of installed plugins