网络:自定义模型转 JSON
来源:互联网 发布:武林外传人物分析 知乎 编辑:程序博客网 时间:2024/05/17 02:42
#import "ViewController.h"#import "Person.h"#import "NSObject+PropertyList.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}// initWithDict- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { Person *person = [[Person alloc]init]; person.name = @"张三"; person.age = 20; // kvc可以给私有的属性赋值 // 只读 [person setValue:@"广州" forKey:@"address"]; // 只读属性// person.phone = @"13800138000"; [person setValue:@"1388" forKey:@"phone"]; // 字典 dictionaryWithValuesForKeys 返回对象字典 NSDictionary *dict = [person dictionaryWithValuesForKeys:[Person propertys]];// NSDictionary *dict = [person dictionaryWithValuesForKeys:@[@"address",@"phone"]]; // 二进制数据 NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL]; // NSURL NSURL *url = [NSURL URLWithString:@"http://localhost/post/postjson.php"]; // NSURLRequest NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; // POST [request setHTTPMethod:@"POST"]; // Body [request setHTTPBody:data]; // NSURLConnection [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) { NSLog(@"%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]); }];}@end
0 0
- 网络:自定义模型转 JSON
- swfit 网络请求对应json转模型!
- JavaScript---网络编程(5)-自定义对象Json、Dom模型概念讲解
- json网络数据转模型结合MJExtension框架
- 自定义网络框架之json文本请求
- Json accelerator --- json 转 模型文件
- ios-json数据转模型
- swift3 模型转字典(JSON)
- Json转模型1--SwiftyJson
- 网络:YYModel 使用(JSON到模型的转换)
- 自定义模型转字典,字典转模型
- JSON模型
- python自定义类型转json
- 自定义json
- 自定义模型
- 网络模型
- 网络模型
- 网络模型
- Lintcode 二叉树的路径和
- MySQL多关键字多字段模糊查询
- bzoj 1009(KMP+矩阵乘法)
- 理解进程调度时机跟踪分析进程调度与进程切换的过程
- iOS应用访问不了网络的解决方法 App Transport Security has blocked a cleartext HTTP
- 网络:自定义模型转 JSON
- 笔试题27. LeetCode OJ (14)
- 开源许可证中文说明
- 重建二叉树
- MySQL5.7的安装与配置
- java工程师常犯的错误
- 设计模式:享元模式(Flyweight)
- Linux应用层系统时间写入RTC时钟的方法
- 一块网卡绑定多个ip