如何处理json字符转换为字典
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@?userName=%@&userPwd=%@",BASE_API,Login,_phoneNumTextField.text,_verificationCodeTextFiled.text]]; AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager POST:URL.absoluteString parameters:nil constructingBodyWithBlock:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { if(IsDictionary(responseObject)){ NSString *str = [responseObject objectForKey:@"status"]; NSDictionary *dic =[self dictionaryWithJsonString:[responseObject objectForKey:@"data"]]; if ([str isEqualToString:@"0"]) { [Util saveResposeDefaults:dic]; MainViewController *mMainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil]; UINavigationController *mUINavigationController = [[UINavigationController alloc] initWithRootViewController:mMainViewController]; [self presentViewController:mUINavigationController animated:YES completion:nil];
mUINavigationController = nil;
}else if ([str isEqualToString:@"2"]){ NSLog(@"密码错误"); }else{ NSLog(@"用户不存在");
} } } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { NSLog(@"Error: %@", error); }];
-(NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString { if (jsonString == nil) { return nil; } NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; NSError *err; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err]; if(err) { NSLog(@"json解析失败:%@",err); return nil; } return dic; }
如何处理json字符转换为字典的更多相关文章
- 关于使用json 字符串转换为字典问题
问题背景: '{"backend": "www.baidu.org", "record": {"server": &qu ...
- jquery中json数据转换为字典
首先在前台页面中的json数据为 var recipe = {}; recipe["name"] = $("#name").val(); recipe[&quo ...
- python将字符转换为字典
参考文章Python 如何将字符串转为字典 注意: 使用json的时候一定要注意是loads而不是load 即:user_dict = json.loads(user_info) 注意: 用eval( ...
- [Swift]JSON字符串与字典(Dictionary)、数组(Array)之间的相互转换
1.JSON字符串与字典(Dictionary)之间的相互转换 import Foundation //JSON字符串转换为字典(Dictionary) func getDictionaryFromJ ...
- json字符转java bean忽略大小写
使用objectMapper进行json字符的解析 com.fasterxml.jackson.databind.ObjectMapper ob =new com.fasterxml.jackson. ...
- 接口测试时数据格式是json,如何将响应内容转换为字典解析
import requests url = 'http://127.0.0.1:5050/index' def apiTestPost(url): datas = { 'a':'cisco3', 'b ...
- JSON+如何处理JSON字符串
JSON(Javascript Object Notation)是一种轻量级的数据交换语言,以文字为基础,且易于让人阅读.尽管JSON是在Javascript的一个子集,但JSON是独立于语言的文本格 ...
- Python 字符串转换为字典(String to Dict)
一.需求 为了处理从redis中拿到的value,如下 {"appId":"ct","crawlSts":false,"healt ...
- Python中 字符串 转换为 字典
需求:把以下字符串转换为字典 #字符串 testStr = '{ "pName": "Ceshi", "gender": 1, " ...
随机推荐
- SQL语法中的JOIN类型
这个要弄明白哟..CROSS JOIN, NATURAL, INNER JOIN ,LEFT OUTER JOIN(LEFT JOIN) 等等....带LEFT,RIGHT的必为OUTER,所以OUT ...
- 使用html5 canvas绘制图片
注意:本文属于<html5 Canvas绘制图形入门详解>系列文章中的一部分.如果你是html5初学者,仅仅阅读本文,可能无法较深入的理解canvas,甚至无法顺畅地通读本文.请点击上述链 ...
- 攻城狮在路上(壹) Hibernate(八)--- 映射Hibernate组成关系
一.使用组成关系的原则: 在不导致数据冗余的前提下,尽可能减少数据库表的数目及表之间的外键参照关系,因为建立多个表的连接是很耗时的操作. 举例说明:Customer类中的Address属性,可以通过组 ...
- WPF QuickStart系列之数据绑定(Data Binding)
这篇博客将展示WPF DataBinding的内容. 首先看一下WPF Data Binding的概览, Binding Source可以是任意的CLR对象,或者XML文件等,Binding Targ ...
- [Tools] 设置surface上的VPN
[背景] 继续前对机器进行配置安装,这次是VPN在win8上的设置,又跟xp不一样,看来要慢慢适应win8的日子,呵呵 [开工] 首先按照原先在win xp上的步骤一步步来配置 选择connect t ...
- FrameLayout
FrameLayout是最简单的布局了. ① 所有放在布局里的控件,都按照层次堆叠在屏幕的左上角.后加进来的控件覆盖前面的控件. ② 该布局container可以用来占有屏幕的某块区域来显示单一的对象
- memset中的sizeof
记录memset中的sizeof的用法, unsigned char *buff = (unsigned char*) malloc(128 * sizeof(char)); //错误的:memset ...
- pythonpython-eggs异常解决方法
: UserWarning: /home/server/.python-eggs is writable by group/others and vulnerable to attack when u ...
- windows下cmd操作
进入文件夹:cd 文件夹名 列出文件列表:dir 清屏:cls
- 用js 向h5 中的table 动态添加数据 (简单实现)
//向 表格传值 function setTextareaValue(items,pp){ console.log(" 进入函数 items=="+items); var tb = ...