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字符转换为字典的更多相关文章

  1. 关于使用json 字符串转换为字典问题

    问题背景: '{"backend": "www.baidu.org", "record": {"server": &qu ...

  2. jquery中json数据转换为字典

    首先在前台页面中的json数据为 var recipe = {}; recipe["name"] = $("#name").val(); recipe[&quo ...

  3. python将字符转换为字典

    参考文章Python 如何将字符串转为字典 注意: 使用json的时候一定要注意是loads而不是load 即:user_dict = json.loads(user_info) 注意: 用eval( ...

  4. [Swift]JSON字符串与字典(Dictionary)、数组(Array)之间的相互转换

    1.JSON字符串与字典(Dictionary)之间的相互转换 import Foundation //JSON字符串转换为字典(Dictionary) func getDictionaryFromJ ...

  5. json字符转java bean忽略大小写

    使用objectMapper进行json字符的解析 com.fasterxml.jackson.databind.ObjectMapper ob =new com.fasterxml.jackson. ...

  6. 接口测试时数据格式是json,如何将响应内容转换为字典解析

    import requests url = 'http://127.0.0.1:5050/index' def apiTestPost(url): datas = { 'a':'cisco3', 'b ...

  7. JSON+如何处理JSON字符串

    JSON(Javascript Object Notation)是一种轻量级的数据交换语言,以文字为基础,且易于让人阅读.尽管JSON是在Javascript的一个子集,但JSON是独立于语言的文本格 ...

  8. Python 字符串转换为字典(String to Dict)

    一.需求 为了处理从redis中拿到的value,如下 {"appId":"ct","crawlSts":false,"healt ...

  9. Python中 字符串 转换为 字典

    需求:把以下字符串转换为字典 #字符串 testStr = '{ "pName": "Ceshi", "gender": 1, " ...

随机推荐

  1. “init terminating in do_boot” Windows10 Rabbit MQ fails to start

    在Windows 10环境下安装rabbitmq-server-3.6.2后,CMD中运行命令:rabbitmq-plugins enable rabbitmq_management 报错: { , ...

  2. 解决phpcms V9 推荐位无法排序

    /phpcms/modules/content/content.php 454行 /** * 排序 */public function listorder() { if(isset($_GET['do ...

  3. 【leetcode】Sqrt(x)

    题目描述: Implement int sqrt(int x). Compute and return the square root of x. 实现开根号,并且返回整数值(这个很重要,不是整数的话 ...

  4. myeclipse+tomcat 工程名改名的问题 ——————完美解决方案

    当建好的工程再重命名之后,发布和访问的时候都还是原来的名字,这个问题纠结了我很久,最好找到解决方法,这里分享一下,希望大家不要再受这种困惑.解决方法: 点击工程右键->properties-&g ...

  5. Effective C++ 之 Item 3:尽可能使用 const

    Effective C++ Chapter 1. 让自己习惯C++(Accustoming Yourself to C++) Item 3. 尽可能使用 const (Use const whenev ...

  6. 一些常用的C++标准函数

    一些常用的C++标准函数 double atof(const char* p); int atoi(const char* p); long atol(const char* p); cstdlib ...

  7. 在Salesforce中可以对某一个Object的Standard Button或Link进行重写

    在Salesforce中可以对某一个Object的Standard Button或Link进行重写,来实现我们特定的逻辑过程,比如:在删除某个Object之前要判断该Object的某个Field的状态 ...

  8. 使用canvas实现擦玻璃效果---转载

    <!DOCTYPE html> <html> <head lang="zh"> <meta name="viewport&quo ...

  9. Loadrunner中参数化实战(1)-Sequential+Each iteration

    参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Sequential+Each iteration 设置迭代4次Action 结果如下:

  10. kafka基本原理学习

    下载安装地址:http://kafka.apache.org/downloads.html  原文链接:http://www.jasongj.com/2015/01/02/Kafka深度解析 Kafk ...