JSON file parsing exception occurred

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.