2

This is the JSON which I receive in message column with emoji:

<span class=\"atwho-inserted\"><img src=\"https://assets-cdn.github.com/images/icons/emoji/smile.png\" height=\"20\" width=\"20\"></span> <span class=\"atwho-inserted\"><img src=\"https://assets-cdn.github.com/images/icons/emoji/person_with_blond_hair.png\" height=\"20\" width=\"20\"></span>
5
  • see this link may be help with you stackoverflow.com/questions/12496860/… Commented Sep 9, 2015 at 5:49
  • Img Src will change often so how should i give it? Commented Sep 9, 2015 at 5:59
  • in HTML tag , image url always start like <img src= Commented Sep 9, 2015 at 6:03
  • @RomiPirisila FYI its not JSON, its pure HTML. You need to use REGEX to extract image. Commented Sep 9, 2015 at 6:04
  • @Dipen Panchasara Its pure Html wch i have to parse using JSON to my IOS APP.....In which no idea how to fetch html image src to IOS APP Commented Sep 9, 2015 at 6:08

1 Answer 1

2
NSString *htmslStr=@"<span class=\"atwho-inserted\"><img src=\"https://assets-cdn.github.com/images/icons/emoji/smile.png\" height=\"20\" width=\"20\"></span> <span class=\"atwho-inserted\"><img src=\"https://assets-cdn.github.com/images/icons/emoji/person_with_blond_hair.png\" height=\"20\" width=\"20\"></span>";

NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(<img\\s[\\s\\S]*?src\\s*?=\\s*?['\"](.*?)['\"][\\s\\S]*?>)+?"
                                                                       options:NSRegularExpressionCaseInsensitive
                                                                         error:&error];

[regex enumerateMatchesInString:htmslStr
                        options:0
                          range:NSMakeRange(0, [htmslStr length])
                     usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {

                         NSString *img = [htmslStr substringWithRange:[result rangeAtIndex:2]];

                         NSURL *candidateURL = [NSURL URLWithString:img];

                         if (candidateURL && candidateURL.scheme && candidateURL.host)
                         {
                             NSLog(@"img src %@",img);
                         }


                     }];

the final Out put is

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

finally use this img string to where you need
in htmslStr --> pass your son string
Thank You @ Anbu.Karthik

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.