問題描述:
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。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持本站。