Today, I'm trying to bring my own Nsjsonserialization method to parse the local JSON file when encountered a system exception, the app automatically terminates
The problem is as follows:
Code:
NSString *newcoursepath = [[NSBundle mainbundle] pathforresource:@ "addcourses" oftype:@ "json"]; NSData *data = [NSData Datawithcontentsoffile:newcoursepath]; Nsarray *array = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingallowfragments Error:nil]; _coursesarray = [[Nsmutablearray alloc] init];
after debugging, it is found that the code
Nsarray *array = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingallowfragments Error:nil];
, there is an exception!
Exceptions are as follows:
* * * * terminating app due to uncaught exception ' nsinvalidargumentexception ', Reason: ' Data parameter is nil '
Indicates that the data obtained from the Addcourse.json in the code is empty!
I then first troubleshoot possible formatting errors in the JSON file and find that the exception is still present.
And the JSON file is actually added to the project.
So, had to put the project JSON file, remove, try to add again, this found the problem!
Drag the file into the project's corresponding file and the following tab pops up:
By default, the file is added to the calendartests and is not added to my calendar.app!
So if you add it directly, the JSON file is actually not being added effectively!
This will require us to select the corresponding Add to targets option inside the Xxx.app tick! this is effectively added!
Exception Exclusions ~
JSON file parsing exception occurred