Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local JSON Parser file added #136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion APCAppCore/APCAppCore.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
0595C6611C84292700210852 /* APCLocalJSONParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 0595C65F1C84292700210852 /* APCLocalJSONParser.h */; };
0595C6621C84292700210852 /* APCLocalJSONParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 0595C6601C84292700210852 /* APCLocalJSONParser.m */; };
08023C4F1AA94F48008E6DDA /* APCAllSetContentViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 08023C4D1AA94F48008E6DDA /* APCAllSetContentViewController.h */; };
08023C501AA94F48008E6DDA /* APCAllSetContentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 08023C4E1AA94F48008E6DDA /* APCAllSetContentViewController.m */; };
08023C531AAA12DF008E6DDA /* APCAllSetTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 08023C511AAA12DF008E6DDA /* APCAllSetTableViewCell.h */; };
Expand Down Expand Up @@ -777,6 +779,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
0595C65F1C84292700210852 /* APCLocalJSONParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APCLocalJSONParser.h; sourceTree = "<group>"; };
0595C6601C84292700210852 /* APCLocalJSONParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APCLocalJSONParser.m; sourceTree = "<group>"; };
08023C4D1AA94F48008E6DDA /* APCAllSetContentViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APCAllSetContentViewController.h; sourceTree = "<group>"; };
08023C4E1AA94F48008E6DDA /* APCAllSetContentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = APCAllSetContentViewController.m; sourceTree = "<group>"; };
08023C511AAA12DF008E6DDA /* APCAllSetTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APCAllSetTableViewCell.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1577,6 +1581,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
0595C65E1C8428FA00210852 /* LocalJSONParser */ = {
isa = PBXGroup;
children = (
0595C65F1C84292700210852 /* APCLocalJSONParser.h */,
0595C6601C84292700210852 /* APCLocalJSONParser.m */,
);
path = LocalJSONParser;
sourceTree = "<group>";
};
08027A3A1A7319AC00B358CC /* Assets */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2424,6 +2437,7 @@
F5B947341A73272C0034C522 /* Library */ = {
isa = PBXGroup;
children = (
0595C65E1C8428FA00210852 /* LocalJSONParser */,
5B0601BF1AE79AE0009D6D65 /* FeedParser */,
F5B947351A73272C0034C522 /* AppearanceHelpers */,
F5B9473C1A73272C0034C522 /* AssertionHandler */,
Expand Down Expand Up @@ -3402,6 +3416,7 @@
F5F12AD21A2F78490015982C /* APCAddressTableViewCell.h in Headers */,
F5F12ADC1A2F78490015982C /* APCSegmentedTableViewCell.h in Headers */,
F5F129E21A2F78490015982C /* APCDataMonitor+Bridge.h in Headers */,
0595C6611C84292700210852 /* APCLocalJSONParser.h in Headers */,
F5B947D31A73272C0034C522 /* UIScrollView+Helper.h in Headers */,
F5F12A811A2F78490015982C /* APCPresentAnimator.h in Headers */,
F5B9462B1A7309A20034C522 /* ZZConstants.h in Headers */,
Expand Down Expand Up @@ -3882,6 +3897,7 @@
F5B947C61A73272C0034C522 /* NSManagedObject+APCHelper.m in Sources */,
F5B947DC1A73272C0034C522 /* APCLog.m in Sources */,
08023C501AA94F48008E6DDA /* APCAllSetContentViewController.m in Sources */,
0595C6621C84292700210852 /* APCLocalJSONParser.m in Sources */,
F5F12AD31A2F78490015982C /* APCAddressTableViewCell.m in Sources */,
F5F12A701A2F78490015982C /* APCCircularProgressView.m in Sources */,
5B827B611A81CAE200C685A3 /* APCDashboardTableViewCell.m in Sources */,
Expand All @@ -3895,7 +3911,6 @@
F5B9480D1A73272C0034C522 /* APCScheduleExpressionTokenizer.m in Sources */,
6C7346091A7ECD3B00DA9CD8 /* APCConsentTaskViewController.m in Sources */,
EE64F4321B02517000A402A7 /* APCOnboardingManager.m in Sources */,
F54DDD281A8026010073E4B4 /* APCDataTracker.m in Sources */,
F5F12A7A1A2F78490015982C /* APCAxisView.m in Sources */,
6CD8B6751AC5011D0061E6D6 /* APCTaskReminder.m in Sources */,
F5B947EC1A73272C0034C522 /* APCDebugWindow.m in Sources */,
Expand Down
40 changes: 40 additions & 0 deletions APCAppCore/APCAppCore/Library/LocalJSONParser/APCLocalJSONParser.h
@@ -0,0 +1,40 @@
//
// APCLocalJSONParser.h
// APCAppCore
//
// Copyright (c) 2015, Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder(s) nor the names of any contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission. No license is granted to the trademarks of
// the copyright holders even if such marks are included in this software.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import <Foundation/Foundation.h>

@interface APCLocalJSONParser : NSObject

+ (NSDictionary *)dictionaryFromJSONFileName:(NSString *)jsonFileName;

@end
58 changes: 58 additions & 0 deletions APCAppCore/APCAppCore/Library/LocalJSONParser/APCLocalJSONParser.m
@@ -0,0 +1,58 @@
//
// APCLocalJSONParser.m
// APCAppCore
//
// Copyright (c) 2015, Apple Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder(s) nor the names of any contributors
// may be used to endorse or promote products derived from this software without
// specific prior written permission. No license is granted to the trademarks of
// the copyright holders even if such marks are included in this software.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//


#import "APCLocalJSONParser.h"
#import "APCLog.h"

@implementation APCLocalJSONParser

+ (NSDictionary *)dictionaryFromJSONFileName:(NSString *)jsonFileName
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:jsonFileName ofType:@"json"];
NSAssert(filePath != nil, @"Unable to location file with Consent Section in main bundle");

NSString *JSONString = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];

NSError *parseError = nil;
NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:[JSONString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&parseError];

if (jsonDictionary != nil) {
return jsonDictionary;
} else {
APCLogError2(parseError);
return nil;
}
}

@end
Empty file.
Expand Up @@ -39,6 +39,7 @@
#import "APCUser+Bridge.h"
#import "APCSpinnerViewController.h"
#import "UIAlertController+Helper.h"
#import "APCLocalJSONParser.h"

static NSString * const kSharingOptionsTableViewCellIdentifier = @"SharingOptionsTableViewCell";
static NSInteger kNumberOfRows = 2;
Expand Down Expand Up @@ -99,14 +100,8 @@ - (void)prepareData

- (void)setupDataFromJSON:(NSString *)jsonFileName
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:jsonFileName ofType:@"json"];
NSString *JSONString = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];

NSError *parseError;
NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:[JSONString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&parseError];


if (!parseError) {
NSDictionary *jsonDictionary = [APCLocalJSONParser dictionaryFromJSONFileName:jsonFileName];
if (jsonDictionary != nil) {
NSDictionary *infoDictionary = jsonDictionary[@"documentProperties"];
self.instituteLongName = infoDictionary[@"investigatorLongDescription"];
self.instituteShortName = infoDictionary[@"investigatorShortDescription"];
Expand Down Expand Up @@ -193,4 +188,5 @@ - (IBAction)close:(id)__unused sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}

@end
Expand Up @@ -39,6 +39,7 @@
#import "UIImage+APCHelper.h"
#import "APCAppCore.h"
#import "APCUser+Bridge.h"
#import "APCLocalJSONParser.h"

@interface APCWithdrawSurveyViewController ()<APCWithdrawDescriptionViewControllerDelegate>

Expand Down Expand Up @@ -173,16 +174,11 @@ - (void) withdrawViewController: (APCWithdrawDescriptionViewController *) __unus

- (NSArray *)surveyFromJSONFile:(NSString *)jsonFileName
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:jsonFileName ofType:@"json"];
NSString *JSONString = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];

NSError *parseError;
NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:[JSONString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&parseError];
NSDictionary *jsonDictionary = [APCLocalJSONParser dictionaryFromJSONFileName:jsonFileName];

NSMutableArray *items = [NSMutableArray new];

if (!parseError) {

if (jsonDictionary != nil) {
NSArray *options = jsonDictionary[@"options"];

NSMutableArray *rowItems = [NSMutableArray new];
Expand Down