ios 提交json boolean 详解iOS开发中解析JSON中的boolean类型的数据遇到的问题
jinrui_w 人气:0想了解详解iOS开发中解析JSON中的boolean类型的数据遇到的问题的相关内容吗,jinrui_w在本文为您仔细讲解ios 提交json boolean的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:ios,提交json,boolean,ios,提交json格式,ios,json,boolean,下面大家一起来学习吧。
问题描述:
Xcode中打印的JSON数据:
{ content = { createTime = 1462512975497; expiryDate = 1475137813; id = 204; intervalSeconds = 0; lastHgt = "63.689"; lastLat = "39.9621096"; lastLng = "116.3175201"; lastTime = 1462848844; manage = 1; nickName = "6ZOD6ZObNzM="; share = 0; tname = 3233470E36343434FF726D73; }; state = success; }
网页请求返回的JSON数据:
{ "content":{ "id":203, "createTime":1462755844018, "share":false, "lastHgt":63.689, "intervalSeconds":0, "nickName":"6ZOD6ZObNzM=", "expiryDate":"1475137813", "tname":"3233470E36343434FF726D73", "lastTime":1462848844, "lastLng":116.3175201, "manage":true,"lastLat":39.9621096}, "state":"success" }
很明显,这里manage字段和share字段明显是boolean类型的数据。但是,用BOOL类接收这两个字段的数据,
NSDictionary *content = [obj objectForKey:@"content"]; BOOL manage = [content objectForKey:@"manage"]; BOOL share = [content objectForKey:@"share"];
得到的结果都为YES,实际上share字段的值应该为NO。
解决办法:
BOOL manage = [[content objectForKey:@"manage"] boolValue]; BOOL share = [[content objectForKey:@"share"] boolValue];
经过这样处理后,得到的manage的值为YES,share的值为NO。
加载全部内容