objective c - Store multiple json object in to a text file iOS -
when there no internet connection on device, storing json in text file. problem is, if again getting replaced. here doing store text file. how store multiple json object in text file.when connection need post json server.
nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *docdir = [paths objectatindex:0]; nsstring *filepath = [docdir stringbyappendingpathcomponent:@"file.json"]; [jsonstring writetofile:filepath atomically:yes encoding:nsutf8stringencoding error:&error];
please advice.
that's not straight forward concatenating multiple json files not result in valid json file. requires read , parse existing json file, give nsarray
or nsdictionary
top-level object, append data new json file , write whole thing out.
that inefficient processing old data.
therefore suggest write new data new file, using current date/time filename, , when it's time upload, read each of files , upload them individually, one-at-a-time. delete each file it's uploaded.
Comments
Post a Comment