11

I am stuck at a point when I convert data from web services to NSDictionary. But while accessing on console in debug mode it returns , while when i bind the values of dictionary with view it works perfectly. Below is the code:-

NSDictionary *responseDict =  [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&e];

and at console i am using po [dictName valueForKey:@"Status"] as well as po [dictName objectForKey:@"Status"]. Followed few steps but does not work for me 1. setting Optimization level to none already in this mode. 2.Edit scheme to debug mode already in this mode.

Trip
  • 26,756
  • 46
  • 158
  • 277
Anupam Gupta
  • 623
  • 1
  • 7
  • 18
  • Have you tried printing the whole dictionary. `po responseDict` – Sachin Vas Dec 02 '16 at 04:16
  • yes whole dictionary is printing the values!!! – Anupam Gupta Dec 02 '16 at 04:17
  • Search through the printed `Dict` whether it has `Status` Key. – Sachin Vas Dec 02 '16 at 04:27
  • 1
    Yes it has the key , even i tried to access some other keys as well but all are returning the same error , I am posting dict '{ ErrorCode = 0; Message = "User login successfully"; ReviewDetail = ""; Status = 1; TotalRecord = 0; UserData = { Aid = 1; Email = ""; IsActive = 1; Name = Administrator; pwd = admin123; usid = admin; }; lstReviewDetail = ""; }' – Anupam Gupta Dec 02 '16 at 04:40
  • What error are you getting. – Sachin Vas Dec 02 '16 at 04:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/129593/discussion-between-new16-and-anupam-gupta). – Sachin Vas Dec 02 '16 at 05:06
  • Can you send your actual JSON. – Sachin Vas Dec 02 '16 at 10:15
  • {"Status":1,"lstReviewDetail":[{"Rid":1,"UploadDate":"Date(1480655794987+0530)","ApplicationId":1,"FolderName":"test","IsDeleted":true,"UsId":1,"FtpPath":"abc.mp3","Title":"test"},{"Rid":4,"UploadDate":"Date(1480572974807+0530)","ApplicationId":1,"FolderName":"tst","IsDeleted":false,"UsId":1,"FtpPath":"test","Title":"test"},{"Rid":5,"UploadDate":"Date(1480575760957+0530)","ApplicationId":1,"FolderName":"test","IsDeleted":false,"UsId":1,"FtpPath":"test,mp3","Title":"test"}],"UserData":null,"ErrorCode":0,"ReviewDetail":null,"TotalRecord":0,"Message":"Success"} – Anupam Gupta Dec 02 '16 at 10:21
  • Well the above JSON is not proper. I corrected it, use the casting to `NSNumber` and then print `po [((NSNumber *)[responseDict valueForKey:@"Status"]) integerValue] `. – Sachin Vas Dec 02 '16 at 11:22
  • 3
    I am having this issue as well. It may be a bug in the debugger interpreter, as my code responds with success but debugging the values gives sporadic issues. – xandermonkey Jan 06 '17 at 05:13

1 Answers1

1

I meet this problem when I try to get information from Info.plist. Finally I use a string exchange.

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Info"ofType:@"plist"];
    NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
    NSString *version = [data objectForKey:@"CFBundleShortVersionString"];
    self.labVersion.text = [NSString stringWithFormat:@"(%@)", version];
Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
Qiang Ye
  • 11
  • 1
  • In addition: then you can cast string value to bool value, for example version.boolValue, or to number value, for example version.numberValue if you want, etc. Bool and may be some other types can incorrect extract from plist-dictionaries, because plist-dictionaries may be is actually have json-format; it is my supposition. String values extract perfectly, however you can see errors while extracting it for example in Xcode-console via po: (po plistDictionary[@"someKeyForExtractingStringValue"]) – pragmus Jul 31 '17 at 09:35