i using twiiter api,trying url json.
the url @ "media_url" deep inside json. how inside json , pull "media_url" out? (the path "media_url" entities->media[8]-->media_url)
i succeded in geting "text" because in high level entities with: @property (strong, nonatomic) nsstring *text; if try @property (strong, nonatomic) nsurl *media_url; nil
this example json:
2017-04-05 12:46:18.272 interview[11043:762614] tweet: { contributors = "<null>"; coordinates = "<null>"; "created_at" = "wed apr 05 09:00:01 +0000 2017"; entities = { hashtags = ( ); media = ( { "display_url" = "pic.twitter.com/twr5y69z3o"; "expanded_url" = "https://twitter.com/forbestech/status/849547162354679808/photo/1"; id = 849547159993274368; "id_str" = 849547159993274368; indices = ( 112, 135 ); "media_url" = "http://pbs.twimg.com/media/c8oypbnxuaarlze.jpg";
parse json nsobject using [nsjsonserialization jsonobjectwithdata:options:error:]. object that's nsarray or nsdictionary. can traverse object so:
nsstring *mediaurl = [[dict[@"tweet"][@"entities"][@"media"] objectatindex:0] objectforkey:@"media_url"]
Comments
Post a Comment