Do not know the small partners, in the development, the process of data debugging, especially in the case of a lot of state debugging, is not always troublesome to the background of the small brother change the state, always feel so much trouble,
Then you can write the data to the local, then go to the sandbox, find the write file, and go directly to change the data in this file. Then you can no longer request the network, you can directly read the file data to debug their own interface,
YXJsonSaveOrLoadTool.h
@interface yxjsonsaveorloadtool:nsobject+ (instancetype) sharetool;//** write Data */-(void) Savejsonwith: (ID) dict Urltype :(NSString *) urltype;//** read Data */-(nsmutabledictionary*) Loadjsonformfile: (NSString *) Urltype; @end
yxjsonsaveorloadtool.m
@implementation yxjsonsaveorloadtool+ (instancetype) sharetool{static dispatch_once_t Oncetoken; Static Yxjsonsaveorloadtool *instance; Dispatch_once (&oncetoken, ^{instance = [[Yxjsonsaveorloadtool alloc]init]; }); return instance;} * * Write Data */-(void) Savejsonwith: (ID) dict urltype: (NSString *) urltype{if (dict = Nil | | dict = = [NSNull null]) { Return } if (urltype.length==0) {urltype = @ "Test"; } nsstring * Path = [self pathfordatafile:urltype]; [Dict Writetofile:path Atomically:yes]; }//** Read Data */-(nsmutabledictionary*) Loadjsonformfile: (NSString *) urltype{nsstring * Path = [self PATHFORDATAFILE:URLT YPE]; Nsmutabledictionary * Rootobject = [[Nsmutabledictionary alloc] initwithcontentsoffile:path]; if (Rootobject = = nil) {rootobject = [[Nsmutabledictionary alloc] initwithcapacity:0]; } return rootobject;} * * Path */-(NSString *) Pathfordatafile: (NSString *) Urltype {nsarray* Documentdir = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES); nsstring* path = nil; if (documentdir) {path = [Documentdir objectatindex:0]; } return [NSString stringwithformat:@ "%@/%@.%@", path,urltype,@ "JSON"];} @end
If there is any wrong place, please do not hesitate to advise,??
Local write and read of JSON, also facilitates debugging of data in development