//
|
// ResponseData.m
|
// EZOpenSDKDemo
|
//
|
// Created by 陈嘉乐 on 2021/3/1.
|
// Copyright © 2021 hikvision. All rights reserved.
|
//
|
|
#import "ResponseData.h"
|
|
@implementation ResponseData
|
|
/// init
|
-(id)init {
|
if (self = [super init]) {
|
self.code = @"-1";
|
self.message = @"请求服务器失败,请稍后再试!";
|
|
}
|
return self;
|
}
|
|
/// 初始化并解析返回字典参数
|
/// @param dic 返回参数
|
- (id)initWithDictionary:(NSDictionary *)dic
|
{
|
if (self = [super init]) {
|
@try {
|
if (dic) {
|
//1.取出返回数据的状态码
|
self.code = [NSString stringWithFormat:@"%@", dic[@"code"]];
|
//2.提示信息
|
self.message = [dic objectForKey:@"message"];
|
//3.返回数据
|
NSDictionary *mData = (NSDictionary *)[dic objectForKey:@"data"];
|
self.data = mData;
|
} else {
|
//没有返回数据
|
self.message = @"请求服务器失败,请稍后再试!";
|
self.data = nil;
|
self.code = @"-1";
|
}
|
}
|
//接收到异常
|
@catch (NSException *exception) {
|
self.message = @"数据解析错误";
|
self.data = dic;
|
self.code = @"-2";
|
}
|
@finally {
|
|
}
|
}
|
return self;
|
}
|
|
/// Description
|
- (BOOL)success
|
{
|
//河东code为0 ,萤石为200 代表成功
|
return [self.code isEqual: @"0"] || [self.code isEqual: @"200"] ;
|
}
|
|
@end
|