Parsing JSON to a predefined class in Objective C

后端 未结 5 1513

I have a json string like:

{
  \"a\":\"val1\",
  \"b\":\"val2\",
  \"c\":\"val3\"
}

And I have an objective C header file like:



        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-02 04:14

    - (id)initWithDictionary:(NSDictionary *)dictionary {
        if (self = [super init]) {
            _a = [dictionary objectForKey:@"a"];
            _b = [dictionary objectForKey:@"b"];
            _c = [dictionary objectForKey:@"c"];
        }
        return self;
    }
    

提交回复
热议问题