json解析嵌套jasn语句报错_Json-Property-Creat-Code

#import "RunTime.h"

typedef struct objc_property *objc_property_t;

@implementation RunTime

//实现单例

+ (NSMutableDictionary *)defaultMyproperty{

//添加线程锁

static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{

if(Myproperty ==nil){

Myproperty=[NSMutableDictionary dictionary];

}

});

return Myproperty;

}

//返回自己这个类的所有属性

- (NSArray *)allProperties {

unsigned int count;

// 获取类的所有属性

// 如果没有属性,则count为0,properties为nil

objc_property_t *properties = class_copyPropertyList([self class], &count);

NSMutableArray *propertiesArray = [NSMutableArray arrayWithCapacity:count];

for (NSUInteger i = 0; i < count; i++) {

// 获取属性名称

const char *propertyName = property_getName(properties[i]);

NSString *name = [NSString stringWithUTF8String:propertyName];

[propertiesArray addObject:name];

}

// 注意,这里properties是一个数组指针,是C的语法,

// 我们需要使用free函数来释放内存,否则会造成内存泄露

free(properties);

return propertiesArray;

}

//返回指定某个类的所有属性

+ (NSArray *)allPropertiesFromObject:(id)object{

unsigned int count;

objc_property_t *properties = class_copyPropertyList([object class], &count);

NSMutableArray *propertiesArray = [NSMutableArray arrayWithCapacity:count];

for (NSUInteger i = 0; i < count; i++) {

const char *propertyName = property_getName(properties[i]);

NSString *name = [NSString stringWithUTF8String:propertyName];

[propertiesArray addObject:name];

}

free(properties);

return propertiesArray;

}

//返回自己这个类的所有属性名和属性值

- (NSDictionary *)allPropertyNamesAndValues{

NSMutableDictionary *resultDict = [NSMutableDictionary dictionary];

unsigned int outCount;

objc_property_t *properties = class_copyPropertyList([self class], &outCount);

for (int i = 0; i < outCount; i++) {

objc_property_t property = properties[i];

const char *name = property_getName(property);

// 得到属性名

NSString *propertyName = [NSString stringWithUTF8String:name];

// 获取属性值

id propertyValue = [self valueForKey:propertyName];

if (propertyValue && propertyValue != nil) {

[resultDict setObj

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值