iPhone Objects from NSDictionary PList -
in app have section load saved plist has 2 nested dictionaries this:
<?xml version="1.0" encoding="utf-8"?> <!doctype plist public "-//apple//dtd plist 1.0//en" "http://www.apple.com/dtds/propertylist-1.0.dtd"> <plist version="1.0"> <dict>     <key>1</key>     <dict>         <key>color</key>         <string>yellow</string>         <key>lang</key>         <string>us</string>         <key>name</key>         <string>peter</string>         <key>uid</key>         <string>1</string>     </dict>     <key>2</key>     <dict>         <key>color</key>         <string>blue</string>         <key>lang</key>         <string>us</string>         <key>name</key>         <string>josh</string>         <key>uid</key>         <string>2</string>     </dict>     <key>3</key>     <dict>         <key>color</key>         <string>red</string>         <key>lang</key>         <string>de</string>         <key>name</key>         <string>susan</string>         <key>uid</key>         <string>3</string>     </dict> </dict> </plist>   now want access string outer dictionary key 2, value inner key color (blue) tried make 2 loops, , works outer dictionary can't access inner
nsmutabledictionary *saveddata = [nsmutabledictionary dictionarywithcontentsoffile:path]; // contains data plist  (int x=0; x<[saveddata count]; x++) {     nsstring *itemnumber = [nsstring stringwithformat:@"%d", x+1];      //this prints out correct inner dictionary     nslog(@"item#%@: %@",itemnumber,[saveddata objectforkey:itemnumber]);       (nsdictionary *dict in [saveddata objectforkey:itemnumber]) {         //prints out color, lang, uid, no key-value pairs          nslog(@"dict: %@",dict);     } }   i'd know how directly access key value pairs inside inner dictionary, give me kick in right direction, please?
how this:
nsstring *bluecolorstring = [[saveddata objectforkey:@"2"] objectforkey:@"color"];   the trick nest method calls, first 1 [saveddata objectforkey:2] returns inner dictionary object on can call method again. hope works intended.
best, robin
Comments
Post a Comment