Search code examples
iosplist

save jsondata to plist by "key":"value" format


Here i have get data and convert it in to nsdictionary and use plist to store. I also put some NSLog to check whether my data have stored or not.but when i read my plist that i have store json .in my console its saying Null.

code is edited

So here is my code.Does any thing i am missing or any other way like "Key"-"Value" format to store my json data to plist.

Your help will move to next feature .Thanks in advance.

If any other method are available with "Key"/"value"- kindly let me know in code.Because i am new to ios & not well in code

This is my Json. Also please see here it having 4 category .In each category it having some id,data,date..

Log output:

plistPath : /Users/maicr/Library/Developer/CoreSimulator/Devices/144C1221-F589-415C-8855-3E5AA06459F8/data/Containers/Data/Application/6F405C7F-43F4-4910-B2CF-15083345F38C/Documents/SampleData.plist
2015-11-03 01:54:12.156 demo[10450:550543] Data successfully saved.
2015-11-03 01:54:12.157 demo[10450:550543] str: (null)

Solution

  • Since you wrote

    convert it in to nsdictionary and use plist to store

    and also the JSON confirms that (it starts with a curly brace), it can't be an array.

    Instead

    NSArray *stringsArray = [NSArray arrayWithContentsOfFile:plistPath];
    

    write

    NSDictionary *stringsDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath];
    

    PS: I recommend to completely use the URL related API