ios - 如何将 AfNetworking 响应对象 (JSON) 映射到自定义类?

标签 ios json xcode5 afnetworking

我得到一个 JSON 作为对使用 AFNetworkingPOST 方法的响应。 我需要将 JSON 映射到自定义类,并创建一个包含来自 JSON 的值的对象。

JSON 字符串

{
branch =     {
    address = "";
    email = "";
    globalId = 174;
    id = 0;
    mobile = 9846147442;
    name = "Sathish Clininc Branch1";
    netMdId = 132;
    numberOfDevices = 0;
    organisationName = "<null>";
    passPhrase =         (
    );
    phone = 04872279166;
    status = active;
};
error = "<null>";
netmd =     {
    globalId = 132;
    headOfficeAddress = "";
    headOfficeEmail = "sreejith@gmail.com";
    headOfficeMobile = "";
    headOfficeName = Koorkenchery;
    headOfficePhone = "";
    id = 0;
    name = "Sathish Clinic";
    ownerAddress = "";
    ownerEmail = "sreejith@gmail.com";
    ownerFirstName = Sathish;
    ownerLastName = Chandran;
    ownerMobile = "";
    ownerPhone = "";
    password = "aW8oFWDMOJUrIV3l7R7hqQ==";
    status = active;
    userName = sathish;
    userType = owner;
};
primary = 1;
retrieveAppointments =     (
);
retrieveDoctorsList =     (
);
retrievePatients =     (
);
retrieveScheduleList =     (
);
success = 1;
user =     (
);    }

自定义类

#import <Foundation/Foundation.h>
#import "ErrorDTO.h"
#import "NetMdBranchDTO.h"
#import "NetMdDTO.h"
@interface NetMdActivationResponseDTO : NSObject
@property (nonatomic, strong)ErrorDTO* error;
@property (nonatomic, assign) BOOL success;
@property (nonatomic, strong) NetMdBranchDTO* branch;
@property (nonatomic, strong) NetMdDTO* netmd;
@property (nonatomic, strong) NSArray* user;
@property (nonatomic, strong) NSArray* retrieveDoctorsList;
@property (nonatomic, strong) NSArray* retrievePatients;
@property (nonatomic, strong) NSArray* retrieveScheduleList;
@property (nonatomic, strong) NSArray* retrieveAppointments;
@property (nonatomic, assign) BOOL primary;

@end

最佳答案

您可以使用 Mantle 提升您的值(value)对象.维护所有转换会更容易。

关于ios - 如何将 AfNetworking 响应对象 (JSON) 映射到自定义类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21623356/

相关文章:

ios - 在 iOS 中以编程方式添加 stackview 时加载缓慢且应用程序崩溃

ios - 如何在 MLMultiarray 元素上应用 Sigmoid?

java - Retrofit2 GET 请求在尝试检索 JSON 数组时返回空列表

ios - 获取 PHAsset 的 url

PHP 创建 JSON 数组列表(数据来自 MySQL)

ios - 如何处理与 Swift 4 Codable 不一致的 JSON 格式?

Xcode 5 复制和粘贴

xcode5 - 在Xcode 5中使用单元测试

ios - 无法保存所有属性集的托管对象

ios - 如何确保 SceneKit 相机始终指向特定位置