-1

I am parsing JSON data and I get a JSON tree like

2015-10-13 15:29:10.563 JsonProject[29154:1434114] requestReply: ( { DNumb = 512421421; DTempData = ""; DUUID = 12; Id = 1; }, { DTempData = ""; Id = 2; },

As you can see here sub key values, I got values under NSCFDictionary data, but i don't know how to parse them. I am new on objective-c and came from .net, is there way to parse these values?

Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102
Mr. Joe
  • 17
  • 1

2 Answers2

0

Following is your reponse ;

equestReply: ( 
    { 
      DNumb = 512421421; DTempData = ""; DUUID = 12; Id = 1;
     },
     { DTempData = ""; Id = 2; 
    })

So you can get values as follows ;

NSMutableArray* dict = [yourResponseObject  ObjectForKey:"equestReply"];
NSString* = [[dict objectAtIndex:index] valueForKey:"DNumb"];
NSString* = [[dict objectAtIndex:index] valueForKey:"DTempData"];
NSString* = [[dict objectAtIndex:index] valueForKey:"DUUID"];
Rohan
  • 2,939
  • 5
  • 36
  • 65
  • No visible @interface for 'NSMutableArray' declares the selector 'objectAtIndex:valueForKey:' what is this? – Mr. Joe Oct 13 '15 at 13:41
0

First you need to convert your JSON data into an NSArray:

NSError *jsonError;
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&jsonError];

then you can access each value using its key like this:

NSDictionary *jsonItemDic = jsonArray[0];
NSString *dTempData = [jsonItemDic objectForkey@"DTempData"]; 

P.S.: The sample data you have sent is incomplete, it seems though that your JSON is an Array of dictionaries. My Answer relies on this theory.

Update:

From the screenshots I have seen, you data is stored inside a root dictionary. That means your object's root is a dictionary with a key called GetVerifiedDevices and the value of an array of dictionaries. You can access the devices array like this:

NSArray *devices = [your_json_object objectForKey:@"GetVerifiedDevices"];

and then query your devices like this:

for(NSDictionary *deviceDic in devices){
  NSString *dTempData = [deviceDic objectForkey@"DTempData"]; 
//And others like above
}

Cheers. M.

Community
  • 1
  • 1
M. Porooshani
  • 1,797
  • 5
  • 34
  • 42
  • get array but after that i get something like that http://s22.postimg.org/xb86u0j7l/Screen_Shot_2015_10_13_at_16_27_57.png, how can i parse key value? – Mr. Joe Oct 13 '15 at 13:30
  • and under this data is : http://s16.postimg.org/5q1rjuj85/Screen_Shot_2015_10_13_at_15_30_03.png – Mr. Joe Oct 13 '15 at 13:32
  • OK, I have seen your Object, it's an array of dictionaries. you see, `NSCFDictionary` is nothing other than the actual `NSDictionary` (CF stands for CoreFoundation) all you have to do is find the dictionary you want and get the value you desire. I'm going to edit my answer. – M. Porooshani Oct 13 '15 at 14:51