json - Edit URL string in iOS -
i have app parses json feed url links , stores url in string. works fine however, url links appear this:
( "http://instagram.com/p/ccefu9huxg/" )
how can rid of brackets , apostrophe's @ end of url?
i need open url in uiwebview can't because of brackets , apostrophe's @ ends of url.
the information json feed being presented in uitableview. when user taps 1 of cells of uitableview, relevant url cell stored in nsstring read uiwebview. here code:
-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { int storyindex = [indexpath indexatposition: [indexpath length] - 1]; nsstring *storylink = [[[[_datasource objectatindex: storyindex] objectforkey:@"entities"] objectforkey:@"urls"] valueforkey:@"expanded_url"]; //[webviewer loadrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:storylink]]]; nslog(@"\n\n link: %@", storylink); [uiview beginanimations:@"animateadbanneron" context:null]; [uiview setanimationduration:1.2]; webviewer.alpha = 1.0; [uiview commitanimations];
}
i story url in nsstring.
here json feed:
{ "coordinates": null, "favorited": false, "truncated": false, "created_at": "sat aug 25 17:26:51 +0000 2012", "id_str": "239413543487819778", "entities": { "urls": [ { "expanded_url": "https://dev.twitter.com/issues/485", "url": "https://t.co/p5bozh0k", "indices": [ 97, 118 ], "display_url": "dev.twitter.com/issues/485" } ], "hashtags": [ ], "user_mentions": [ ] }
thanks, dan.
your nslog
output indicates
nsstring *storylink = [[[[_datasource objectatindex: storyindex] objectforkey:@"entities"] objectforkey:@"urls"] valueforkey:@"expanded_url"];
does not return nsstring
expected, nsarray
. value of "urls"
in json object array of dictionaries , not single dictionary? in case following should work:
nsstring *storylink = [[[[[_datasource objectatindex: storyindex] objectforkey:@"entities"] objectforkey:@"urls"] objectatindex:0] objectforkey:@"expanded_url"];
a more concrete answer might possible if show json output.
remark:
int storyindex = [indexpath indexatposition: [indexpath length] - 1];
can simplified
int storyindex = indexpath.row;
(see "nsindexpath uikit additions".)
update: localize problem further, recommend split code separate commands, , check if "urls"
array empty or not:
nsdictionary *dict = [_datasource objectatindex: storyindex]; nsdictionary *entities = [dict objectforkey:@"entities"]; nsarray *urls = [entities objectforkey:@"urls"]; if ([urls count] > 0) { nsdictionary *firsturl = [urls objectatindex:0]; nsstring *storylink = [firsturl objectforkey:@"expanded_url"]; nslog(@"link: %@", storylink); } else { nslog(@"urls empty array!!"); }
if still crashes, set "breakpoint on objective-c exceptions" check crashes exactly.
Comments
Post a Comment