objective c - JSONKit returning unwanted NSCFString rather than NSDictionary -
i've been pulling hair out tried figure out whats wrong here, reason jsonkit
isn't giving me dictionary need can reference particular key/value pairs within plist.
instead displaying nscfstring
doesn't conform methods objectforkey:
. i've scoured around solutions; telling me disable arc, restart/reinstall xcode, , variety of different implementations no budging. worse yet, have same code block in project same function , works seamlessly.
nserror * error = null; nsdata * plistdata = [nsdata datawithcontentsoffile:filepath]; id plist = [nspropertylistserialization propertylistwithdata:plistdata options:nspropertylistimmutable format:null error:&error]; nsstring * jsonstring = [plist jsonstringwithoptions:jkserializeoptionpretty error:&error]; nsdictionary * returndictionary = [jsonstring objectfromjsonstring]; for(id elem in returndictionary) { for(id elements in elem) { nslog(@"%@",elements); } }
the error given:
-[nscfstring countbyenumeratingwithstate:objects:count:]: unrecognized selector sent instance 0x1815750
the plist in question:
<dict> <key>20003</key> <dict> <key>type</key> <string>1</string> <key>name</key> <string>home name</string> <key>font</key> <string>courier</string> <key>size</key> <string>22</string> <key>color</key> <string>ffffffff</string> </dict> <key>20001</key> <dict> <key>type</key> <string>1</string> <key>name</key> <string>heyhey</string> <key>font</key> <string>xxx</string> <key>size</key> <string>11</string> <key>color</key> <string>ffff0000</string> </dict> </dict> </plist>
problem not jsonkit not returning nsdictionary.
problem when enumerate through nsdictionary, "key", not "value".
so, following codes:
for(id elem in returndictionary) { for(id elements in elem) { nslog(@"%@",elements); } }
the type of elem in outer loop "key" each entry in dictionary. (which, plist, is string)
change
for(id elem in returndictionary) { id val = returndictionary[ elem ]; for(id elements in val) { nslog(@"%@",elements); } }
see if helps
Comments
Post a Comment