您好,我是 iPhone 开发的新手。我尝试将 NSDictionary 中的移动数据添加到我创建的调用的数据成员中。当我“setWeightMeasure”什么也没发生。
有什么建议么?
不起作用的代码:
NSDictionary *responseBodyProfile = [responseBody objectFromJSONString];
NSLog(@"%@",responseBodyProfile);
// the output is :
"{ "profile": {"goal_weight_kg": "77.0000", "height_cm": "179.00",
"height_measure": "Cm", "last_weight_date_int": "15452",
"last_weight_kg": "99.0000", "weight_measure": "Kg" }}""
[responseBody release];
if (responseBodyProfile != nil ){
NSDictionary *profile =[responseBodyProfile valueForKey:@"profile"];
NSLog(@"%@\n",[profile objectForKey:@"weight_measure"]);// Output : "kg"
[self.myUser setWeightMeasure:[profile objectForKey:@"weight_measure"]];
NSLog(@"%@", [self.myUser WeightMeasure]); // Output : "(null)"
}
H文件属性:
@property (nonatomic, retain) UserData* myUser;
用户数据.h:
#import <Foundation/Foundation.h>
@interface UserData : NSObject{
NSString* Weight;
NSString* Height;
NSString* GolWeight;
NSString* WeightMeasure;
}
@property (nonatomic, retain) NSString* Weight;
@property (nonatomic, retain) NSString* Height;
@property (nonatomic, retain) NSString* GolWeight;
@property (nonatomic, retain) NSString* WeightMeasure;
@end
用户数据.m
#import "UserData.h"
@implementation UserData
@synthesize Weight, Height, GolWeight, WeightMeasure;
-(id)init{
self.Weight = @"0";
self.Height = @"0";
self.GolWeight = @"0";
self.WeightMeasure = @"0";
return self;
}
-(void)dealloc{
[Weight release];
[Height release];
[GolWeight release];
[WeightMeasure release];
[super dealloc];
}
@end