Search code examples
iosobjective-cjsontwittertwitter-streaming-api

iOS: Path to Twitter URL using JSON?


I'm trying to pull in the first url of a tweet using -objectForKey:, and I was wondering how I can pull in the expanded url in 1 go.

Here's the json:

"entities":{
      "hashtags":[

      ],
      "symbols":[

      ],
      "urls":[
         {
            "url":"http:\/\/t.co\/example",
            "expanded_url":"http:\/\/example.com\/hi",
            "display_url":"example.com\/hi",
            "indices":[
               46,
               68
            ]
         }
      ],
      "user_mentions":[

      ]
   },

This is what I tried: NSLog(@"URL FOUND: %@", [JSON objectForKey:@"entities/urls/expanded_url"]); but I got (null).


Solution

  • This code will be help for you

    NSArray *urls = [[JSON objectForKey:@"entities"] objectForKey:@"urls"];
    NSString *url = [[urls objectAtIndex:0] objectForKey:@"url"];
    NSLog(@"%@",url);