如何处理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, " ...
随机推荐
- C# IP地址与整数之间的转换
IP地址与整数之间的转换 1.IP地址转换为整数 原理:IP地址每段可以看成是8位无符号整数即0-255,把每段拆分成一个二进制形式组合起来,然后把这个二进制数转变成一个无符号的32位整数. 举例:一 ...
- Auto Layout
Auto Layout XCode5+ Auto Layout Concepts 核心的概念是约束. Constraint Basics Constant value Relation Priorit ...
- C#交互功能的演化
(此文章同时发表在本人微信公众号“dotNET每日精华文章”,欢迎右边二维码来关注.) 题记:Miguel de Icaza在最近发表的一篇博文中畅谈了Mono及其相关产品中的C#交互特性的演化情况. ...
- 用Node.js开发Windows 10物联网应用
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 未来10年内,物联网将会如移动互联网这样深入到我们生活的各方各面.所以微软现在对物联网进行了 ...
- linux下搭建属于自己的博客(WordPress安装)
转自:http://www.cnblogs.com/xiaofengkang/archive/2011/11/16/2251608.html WordPress简介 WordPress 是一种使用 P ...
- UE对一个很长的字符按16位自动换行
① ②设定16个位 ③ ④结果
- UIPopoverController 的使用
#import "ViewController.h" #import "RYColorSelectController.h" #import "RYM ...
- 及其简短的Splay代码
#include <stdio.h> #include <queue> #include <algorithm> #include <stdlib.h> ...
- js String对象
字符串(String) 字符串(String)使用长度属性length来计算字符串的长度: 在字符串中查找字符串 字符串使用 indexOf() 来定位字符串中某一个指定的字符首次出现的位置: 实例 ...
- Python入门之树莓派
Linux命令行$+命令 pwd显示当前目录 ls列表 cd改变当前目录,/ sudo超级用户输入,特权来操作系统相关设置或删除文件 sudo apt-get install 安装程序 sudo ...