iOS: Serialize/Deserialize complex JSON generically from NSObject class

后端 未结 3 707
栀梦
栀梦 2020-11-27 07:45

Anyone have idea how to serialize nested JSON based on NSObject class? There is a discussion to serialize simple JSON here , but it is not generic enough to cater complex n

3条回答
  •  自闭症患者
    2020-11-27 08:18

    Maybe this one can help BWJSONMatcher. It helps you easily match a JSON string or JSON object up with your data model with one line of code.

    ...
    NSString *jsonString = @"{your-json-string}";
    YourValueObject *dataModel = [YourValueObject fromJSONString:jsonString];
    
    NSDictionary *jsonObject = @{your-json-object};
    YourValueObject *dataModel = [YourValueObject fromJSONObject:jsonObject];
    ...
    YourValueObject *dataModel = instance-of-your-value-object;
    NSString *jsonString = [dataModel toJSONString];
    NSDictionary *jsonObject = [dataModel toJSONObject];
    ...
    

提交回复
热议问题