iOS JSONModel json实例

时间:2014-04-15 16:36:03

标签: ios

我正在尝试在我正在构建的应用中使用此JSONModel library。我一直关注this article,但由于某种原因,我在尝试解析json字符串时一直得到(null)。我被告知这是因为我没有创建一个json实例;但在我看来,我。以下是代码,任何人都能看到我错过的内容吗?我尝试使用this web service这些输入:      emailAddress:wufpakjack@yahoo.com;      密码:测试;      companyId:2579;      scheduleDate:20140415。

myShiftModel.h

#import "JSONModel.h"

@interface myShiftModel : JSONModel

@property (assign, nonatomic) NSString *shiftName;
@property (assign, nonatomic) NSString *shiftStartTime;
@property (assign, nonatomic) NSString *shiftPosition;

@end

dailyViewModel.h

#import "JSONModel.h"
#import "myShiftModel.h"

@protocol dailyViewModel @end

@interface dailyViewModel : JSONModel

@property (assign, nonatomic) int numAvailableXChanges;
@property (strong, nonatomic) NSString *todaysForecast;
@property (assign, nonatomic) int todaysTemperature;
@property (strong, nonatomic) myShiftModel *workShift;

@end

dailyFeed.h

#import "JSONModel.h"
#import "dailyViewModel.h"

@interface dailyFeed : JSONModel

@property (strong, nonatomic) NSArray <dailyViewModel> *workShifts;

@end

mainViewController.m

#import "mainViewController.h"
#import "JSONModelLib.h"
#import "JSONModel+networking.h"
#import "dailyFeed.h"


@interface mainViewController () {
    dailyFeed *feed;
}
@end

@implementation mainViewController

- (void)viewDidAppear:(BOOL)animated {
    NSString *email = [[NSString alloc]initWithFormat:@"wufpakjack@yahoo.com"];
    NSString *pass = [[NSString alloc]initWithFormat:@"test"];
    NSString *compID = [[NSString alloc]initWithFormat:@"2579"];
    NSString *date = [[NSString alloc]initWithFormat:@"20140415"];

    NSString *urlString = [NSString stringWithFormat:@"http://qa.shiftzen.com/ws/schedutils.asmx/GetDailyView?emailAddress=%@&password=%@&companyId=%@&scheduleDate=%@", email,pass,compID,date];
    NSLog(@"%@", urlString);

    [JSONHTTPClient getJSONFromURLWithString:urlString
                                  completion:^(NSDictionary *json, JSONModelError *err) {

                                      NSError* error = nil;
                                      feed = [[dailyFeed alloc] initWithDictionary:json error:&error];

                                      NSLog(@"shifts: %@", feed.workShifts);

                                  }];
}
@end

非常感谢任何指导。

最热烈的问候, DB

0 个答案:

没有答案