目标c iOS传递数据

目标c iOS传递数据,ios,objective-c,iphone,nsstring,Ios,Objective C,Iphone,Nsstring,嗨,我是iOS新手,下面是我的代码,我必须通过请求-回复的顶部…请帮助我,我被困在这里 第一个视图控制器是otp视图,第二个vc是verifyviewcontroller Otp视图c.h #import <UIKit/UIKit.h> @interface OtpViewController : UIViewController @property (nonatomic, retain) NSString *str; @end 在nslog上,我得到的回复是(“成功”:“1”;“

嗨,我是iOS新手,下面是我的代码,我必须通过请求-回复的顶部…请帮助我,我被困在这里 第一个视图控制器是otp视图,第二个vc是verifyviewcontroller

Otp视图c.h

#import <UIKit/UIKit.h>
@interface OtpViewController : UIViewController
@property (nonatomic, retain) NSString *str;
@end

在nslog上,我得到的回复是(“成功”:“1”;“otp”:“985123”),我需要在下一页中存储和验证此otp。请帮助首先您需要更改属性

来自

@property (weak,nonatomic) NSArray *tmp;

 @property (strong,nonatomic) NSStirng *tmp;
将值分配给tmp,如下所示

[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
           NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; // this is json string
           NSError *error;
           NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; // you need to convert to dictionary object

            NSLog(@"requestReply: %@", jsonDict);
            self.tmp=[jsonDict valueForKey:@"otp"] ; // you need to extract value using the key   [requestReply valueForKey:@"otp"];
            NSLog(@"%@",self.tmp);

    }] resume];
将tmp传递给VerifyVIewController

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender{

VerifyViewController *loadCtr = (VerifyViewController *)segue.destinationViewController;
loadCtr.delegate = self;
loadCtr.tmpStr = self.tmp;
NSLog(@"passing val: %@",_tmp);
}

你可以找到helpfull.2017-05-31 12:10:12.540菜单栏[1315:76259]数据详细信息是phone=9047038606 2017-05-31 12:10:12.554菜单栏[1315:76259]passing val:(null)2017-05-31 12:10:13.267菜单栏[1315:76307]请求回复:{“成功”:1,“otp”:“118301”}2017-05-31 12:10:13.268菜单栏[1315:76307]{“成功”:1,“otp”:“118301”}2017-05-31 12:10:13.269菜单栏[1315:76307]{“成功”:1,“otp”:“118301”}@EvgeniyKleban我已经检查过了,但是答案通过了布尔值。你能解释一下你想做什么吗?我需要这个顶部来存储可以纠正吗?top还是otp?谢谢你的努力!!我在log2017-05-31 12:43:32.741菜单栏[1398:90037]传递值:(null)2017-05-31 12:43:33.464菜单栏[1398:90096]请求回复:{“成功”:1,“otp”:“753161”}2017-05-31 12:43:33.464菜单栏[1398:90096]{“成功”:1,“otp”:“753161”}您需要提取值。self.tmp=[requestReply valueForKey:@“otp”];2017-05-31 12:51:08.063菜单栏[1435:93502]***由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[valueForUndefinedKey:]:此类不符合密钥otp的键值编码要求。”***第一次抛出调用堆栈:
 @property (strong,nonatomic) NSStirng *tmp;
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
           NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; // this is json string
           NSError *error;
           NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; // you need to convert to dictionary object

            NSLog(@"requestReply: %@", jsonDict);
            self.tmp=[jsonDict valueForKey:@"otp"] ; // you need to extract value using the key   [requestReply valueForKey:@"otp"];
            NSLog(@"%@",self.tmp);

    }] resume];
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender{

VerifyViewController *loadCtr = (VerifyViewController *)segue.destinationViewController;
loadCtr.delegate = self;
loadCtr.tmpStr = self.tmp;
NSLog(@"passing val: %@",_tmp);
}