ios - Use string as part of [JSON valueForKeyPath] selector? -


i'm parsing json looks like:

{"data":{"items":{"daily":{"2013-07-31":16}}}} 

i've built date string. e.g:

nsdateformatter *format = [[nsdateformatter alloc] init]; [format setdateformat:@"y-mm-d"];  nsdate *now = [[nsdate alloc] init]; nsstring *datestring = [format stringfromdate:now]; 

how use datestring part of valueforkeypath selector?

[json valueforkeypath:@"data.items.daily"]? 

you can create keypath string using +stringwithformat: method , use it. have (assuming json object parsed json string):

nsstring *keypath = [nsstring stringwithformat:@"data.items.daily.%@", datestring]; id valueyoulookfor = [json valueforkeypath: keypath] 

Comments

Popular posts from this blog

android - Inheriting from Theme.AppCompat* -

broadcastreceiver - android BOOT_COMPLETED not received if not activity intent-filter -

basic authentication with http post params android -