序列化
来源:互联网 发布:网络成瘾案例 编辑:程序博客网 时间:2024/05/29 04:40
往服务器POST JSON & XML没有办法通过浏览器测试
1,JSON 序列化
(1),JSON序列化只支持字典或者数组
反序列化 JSONObjectWithData 序列化 dataWithJSONObject
(2),检测对象是否是有效的JSON对象
[NSJSONSerialization isValidJSONObject:obj]
2,对象序列化
实现原理:先将对象转成字典或者数组,然后JSON序列化
(1),用KVC将对象转字典
NSDictionary *dict = [p1dictionaryWithValuesForKeys:@[@"username",@"age"]];
( 对比:[selfsetValuesForKeysWithDictionary:dict]; )
接着将dict进行JSON序列化
3,plist序列化
(1)
反序列化 propertyListWithData
序列化 dataWithPropertyList
(2),检测对象是否是有效的plist对象
+ (BOOL)propertyList:(id)plist isValidForFormat:(NSPropertyListFormat)format;
(3),代码示例
1,JSON 序列化
(1),JSON序列化只支持字典或者数组
反序列化 JSONObjectWithData 序列化 dataWithJSONObject
(2),检测对象是否是有效的JSON对象
[NSJSONSerialization isValidJSONObject:obj]
2,对象序列化
实现原理:先将对象转成字典或者数组,然后JSON序列化
(1),用KVC将对象转字典
NSDictionary *dict = [p1dictionaryWithValuesForKeys:@[@"username",@"age"]];
( 对比:[selfsetValuesForKeysWithDictionary:dict]; )
接着将dict进行JSON序列化
3,plist序列化
(1)
反序列化 propertyListWithData
序列化 dataWithPropertyList
(2),检测对象是否是有效的plist对象
+ (BOOL)propertyList:(id)plist isValidForFormat:(NSPropertyListFormat)format;
(3),代码示例
- (void)plistSerialization { // 自定义对象=>plist的序列化 NSDictionary *dict1 = @{@"username": @"zhangsan", @"age": @(18)}; NSDictionary *dict2 = @{@"username": @"list", @"age": @(18)}; NSArray *array = @[dict1, dict2]; Person *p1 = [Person personWithDict:dict1]; // 将字典序列化成plist// [NSJSONSerialization dataWithJSONObject:<#(id)#> options:<#(NSJSONWritingOptions)#> error:<#(NSError *__autoreleasing *)#> if ([NSPropertyListSerialization propertyList:p1 isValidForFormat:NSPropertyListXMLFormat_v1_0]) { NSData *data = [NSPropertyListSerialization dataWithPropertyList:p1 format:NSPropertyListXMLFormat_v1_0 options:0 error:NULL]; // 将data写入文件 [data writeToFile:@"/Users/apple/Desktop/123.plist" atomically:YES]; } else { NSLog(@"格式不正确"); }}
0 0
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 序列化
- 不知不觉
- Codevs 1009 产生数
- 第二周工作周报
- 在发现问题时我们不可听之任之
- 即指的是baidu的反向连署
- 序列化
- Ubuntu12.04上面用CPU编译使用caffe(不完全安装)
- 2.x终于照着教程,成功使用OpenGL ES 绘制纹理贴图,增加了灰度图
- Video Object Segmentation through Spatially Accurate and Temporally Dense Extraction of Primary Object Regions
- 重要知识结构-持续更新中
- Visual Studio 2010 + CLAPACK
- VS2010编译安装OpenCV2.4.3
- Spectral Grouping Using The Nystrom Method
- nmake