ios - Parse local json to UILabels -


i'm trying parse json file can use it's contents nsstrings , display in uilabels throughout application.

my json:

{     "customtext": [         {             "bodytext": "this body text",             "logintext": "this logintext",             "extratext": "this text"         }     ] } 

my code:

nsstring *filepath = [[nsbundle mainbundle] pathforresource:@"file" oftype:@"json"];  nsdata *content = [[nsdata alloc] initwithcontentsoffile:filepath]; nsmutabledictionary *json = [nsjsonserialization jsonobjectwithdata:content options:kniloptions error:nil];  nsarray *customstrings = json[@"customtext"]; nsstring *body = [customstrings valueforkey:@"bodytext"]; nsstring *login = [customstrings valueforkey:@"logintext"]; self.labeltext.text = body; 

i'm not sure why breaks, have looks , surprisingly didn't find on how best use local json file. great.

error message:

terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nsarrayi length]: unrecognized selector sent instance 0x7f8080781740'

nsstring *filepath = [[nsbundle mainbundle] pathforresource:@"file" oftype:@"json"];   nsdata *content = [[nsdata alloc] initwithcontentsoffile:filepath];    nsmutabledictionary *json = [nsjsonserialization jsonobjectwithdata:content options:kniloptions error:nil];  nsarray *customstrings = json[@"customtext"]; nsstring *body = [[customstrings objectatindex:0] valueforkey:@"bodytext"]; nsstring *login = [[customstrings objectatindex:0] valueforkey:@"logintext"]; self.labeltext.text = body; 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -