How to convert data to JSON format, using SBJSON iPhone SDK? - objective-c

I want to convert the given data to JSON format ... please help me to overcome this problem. Thanks in advance.
{
data = (
{
id = 1307983297;
name = "Aafaaq Mehdi";
},
{
id = 1350886273;
name = "Shah Asad";
},
{
id = 1636300537;
name = "Imran Baig";
},
{
id = 1640049813;
name = "Vinod Gowda";
}
);
}
UPDATE:
NSDictionary *dict = [[NSDictionary alloc] initWithDictionary:appDelegate.friendList];
results= (NSArray *)[dict valueForKey:#"data"];
NSMutableArray *arr = [[NSMutableArray alloc] init];
// loop over all the results objects and print their names
int ndx;
for (ndx = 0; ndx < results.count; ndx++)
{
[arr addObject:(NSDictionary *)[results objectAtIndex:ndx]];
}
FriendListModel *obj;
for (int x=0; x<[arr count]; x++)
{
obj = [[[FriendListModel alloc] initWithjsonResultDictionary:[arr objectAtIndex:x]] autorelease];
[arr replaceObjectAtIndex:x withObject:obj];
NSMutableArray *facebookJSON = [[[NSMutableArray alloc] init] autorelease];
for (obj in arr) {
NSDictionary *syedDict = [NSDictionary dictionaryWithObjectsAndKeys:obj.friendId,#"id", obj.friendName, #"name", nil];
NSString *facebookJSONFormat = [syedDict JSONRepresentation];
[facebookJSON addObject:facebookJSONFormat];
}
NSString *myArrayString = [facebookJSON description];
NSString *braceInArr = [NSString stringWithFormat:#"[%#]", myArrayString];
[self setFormDataRequest:[ASIFormDataRequest requestWithURL:url]];
[formDataRequest setDelegate:self];
[formDataRequest setPostValue:braceInArr forKey:#"friend_list"];
[formDataRequest setDidFailSelector:#selector(uploadFailed:)];
[formDataRequest setDidFinishSelector:#selector(uploadFinished:)];
[formDataRequest startAsynchronous];
I got the output in this format:-
[(
"{\"id\":\"1307983297\",\"name\":\"No Man\"}",
"{\"id\":\"1350886273\",\"name\":\"Shah Asad\"}",
"{\"id\":\"1636300537\",\"name\":\"Imran Baig\"}",
"{\"id\":\"1640049813\",\"name\":\"Vinod Gowda\"}"
)]

{
"data":[
{
"id": 1307983297,
"name": "Aafaaq Mehdi"
},
{
"id": 1350886273,
"name": "Shah Asad"
},
{
"id": 1636300537,
"name": "Imran Baig"
},
{
"id": 1640049813,
"name": "Vinod Gowda"
}
]
}
That's your dad in JSON format... as for converting it, do you have a parser for the original format?

Related

How to get array object values from JSON response?

I have a json response in this format please look at this.I want to get lat and long values for every address.
{
"message":"success",
"data":
{
"docs":
[
{
"_id":"573d8eca67c7f172cc88387e",
"user":
{
"phone":"8510932519)/+",
"image":"",
"name":"Niraj#%"
},
"distance":18825,
"bookingNumber":"42aopy2dyry8",
"bookingType":0,
"paymentMode":"Card",
"tip":0,
"estimatedFare":51.1,
"estimatedDuration":"2364",
"created":"2016-05-18T14:49:31.231Z",
"stop2":
{
"address":"Malviya Nagar, New Delhi, Delhi 110017, India",
"location":[28.533519700000003,77.21088569999999]
},
"stop1":
{
"address":"Ansari Nagar East, New Delhi, Delhi 110029, India",
"location":
[
28.566540099999997,
77.2098409
]
},
"destination":
{
"address":"Saket, New Delhi, Delhi 110017, India",
"location":
[
28.524578699999996,
77.206615
]
},
"currentLocation":
{
"address":"26, Ashok MargJ Block, Pocket J, Sector 18",
"location":
[
28.568437,
77.32404
]
}
}
],
"total":1,
"limit":8,
"page":":1",
"pages":1
}
}
i need to get lat and long for every address. i am using this code for get the address, but how will i get lat and long for 0 and 1 index in location array?
dictionary = [[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]objectForKey:#"data"];
NSArray *IDArray = [dictionary objectForKey:#"docs"];
for (NSDictionary *Dict in IDArray)
{
NSMutableDictionary *temp = [NSMutableDictionary new];
[temp setObject:[Dict objectForKey:#"_id"] forKey:#"_id"];
NSString *booknumber = [Dict objectForKey:#"bookingNumber"];
if([booknumber length] != 0)
[temp setObject:booknumber forKey:#"bookingNumber"];
NSMutableDictionary *stp1 = [Dict objectForKey:#"stop1"];
if ([[stp1 allKeys] containsObject:#"address"]) {
[temp setObject:[stp1 objectForKey:#"address"] forKey:#"address"];
}
NSMutableDictionary *stp2 = [Dict objectForKey:#"stop2"];
if ([[stp2 allKeys] containsObject:#"address"]) {
[temp setObject:[stp2 objectForKey:#"address"] forKey:#"address1"];
}
NSMutableDictionary *currentloc = [Dict objectForKey:#"currentLocation"];
if ([[currentloc allKeys] containsObject:#"address"]) {
[temp setObject:[currentloc objectForKey:#"address"] forKey:#"address1"];
}
try this
NSMutableDictionary *stp1 = [Dict objectForKey:#"stop1"];
if ([[stp1 allKeys] containsObject:#"address"]) {
[temp setObject:[stp1 objectForKey:#"address"] forKey:#"address"];
// take one Temp array for fetch lat and long
NSArray *tempstp1 = [stp1 objectForKey:#"location"];
[temp setObject:[tempstp1 objectAtIndex:0] forKey:#"latitude"];
[temp setObject:[tempstp1 objectAtIndex:1] forKey:#"longitude"];
}
NSMutableDictionary *stp2 = [Dict objectForKey:#"stop2"];
if ([[stp2 allKeys] containsObject:#"address"]) {
[temp setObject:[stp2 objectForKey:#"address"] forKey:#"address"];
// take one Temp array for fetch lat and long
NSArray *tempstp2 = [stp2 objectForKey:#"location"];
[temp setObject:[tempstp2 objectAtIndex:0] forKey:#"latitude"];
[temp setObject:[tempstp2 objectAtIndex:1] forKey:#"longitude"];
}

How to check that the incoming JSON feed contains a single record or multiple?

I have to parse this JSON on iOS.
{
"log_by_dates": {
"logs": [
{
"date": "Wednesday 5 December 2012",
"exercises": "0",
"workouts": "0",
"log_entries": "0"
},
{
"date": "Tuesday 4 December 2012",
"exercises": "4",
"workouts": "2",
"log_entries": "7"
}
]
}
}
I have written following code to parse it;
NSArray *logs = [[(NSDictionary*)results objectForKey:#"log_by_dates"] objectForKey:#"logs"];
for (NSDictionary *aLog in logs) {
Log *newLog = [[Log alloc] initWithDate:[aLog objectForKey:#"date"] withExercises:[aLog objectForKey:#"exercises"]
withWorkouts:[aLog objectForKey:#"workouts"]];
if (!data) {
data = [[NSMutableArray alloc] init];
}
But problem is that, sometimes I get the JSON value like this;
{
"log_by_dates": {
"logs":
{
"date": "Wednesday 5 December 2012",
"exercises": "0",
"workouts": "0",
"log_entries": "0"
}
}
}
Which makes my code to crash.
Please guide me, which if() else condition I use to check that whether the incoming JSON object contains multiple records of the single one before parsing so that I code write appropriate code to handle the dictionary or array.
Thanks,
Please update your code like this.
NSArray *logs = [[(NSDictionary*)results objectForKey:#"log_by_dates"] objectForKey:#"logs"];
if([logs isKindOfClass:[NSArray class]]) {
for (NSDictionary *aLog in logs) {
Log *newLog = [[Log alloc] initWithDate:[aLog objectForKey:#"date"] withExercises:[aLog objectForKey:#"exercises"]
withWorkouts:[aLog objectForKey:#"workouts"]];
if (!data) {
data = [[NSMutableArray alloc] init];
}
}
}
else if([logs isKindOfClass:[NSDictionary class]]) {
NSDictionary *aLog = (NSDictionary *)logs;
Log *newLog = [[Log alloc] initWithDate:[aLog objectForKey:#"date"] withExercises:[aLog objectForKey:#"exercises"]
withWorkouts:[aLog objectForKey:#"workouts"]];
if (!data) {
data = [[NSMutableArray alloc] init];
}
}
Check the condition like
if([[[(NSDictionary*)results objectForKey:#"log_by_dates"] objectForKey:#"logs"] isKindOfClass:[NSArray class]])
{
// Do your Array Stuff Here
} else {
// Do your Dictionary Stuff Here
}
Insert this before your for loop:
if (![logs isKindOfClass:[NSArray class]])
{
logs = [NSArray arrayWithObject:logs];
}

Split an NSArray in smaller key value coded arrays using a common key-value pair between objects

I'm trying to find a good solution to split an array of dictionaries in a smaller dictionaries keyed by a common value between them.
Here is an example i JSON, I start from this:
{
"field": [
{
"id": 6,
"name": "Andrea"
},
{
"id": 67,
"name": "Francesco"
},
{
"id": 8,
"name": "Maria"
},
{
"id": 6,
"name": "Paolo"
},
{
"id": 67,
"name": "Sara"
}
]
}
I'd like to get a result like:
{
"field": [
{
"6": [
{
"name": "Andrea",
"id": 6
},
{
"name": "Paolo",
"id": 6
}
],
"67": [
{
"name": "Sara",
"id": 67
},
{
"name": "Francesco",
"id": 67
}
],
"8": [
{
"name": "Maria",
"id": 8
}
]
}
]
}
I managed using this code, it works, but I'm wondering if exist something more correct and fast:
NSArray * array = ...;
NSSortDescriptor *sorter1=[[NSSortDescriptor alloc]initWithKey:#"id" ascending:YES selector:#selector(compare:)];
NSSortDescriptor *sorter2=[[NSSortDescriptor alloc]initWithKey:#"name" ascending:YES selector:#selector(caseInsensitiveCompare:)];
NSArray *sortDescriptors=[NSArray arrayWithObjects:sorter1,sorter2,nil];
array = [array sortedArrayUsingDescriptors:sortDescriptors];
//////////////////////////////SPLITTER
NSMutableArray * subcategorySplittedArray = [[NSMutableArray alloc]initWithCapacity:30];
NSNumber * lastID=[[array objectAtIndex:0]objectForKey:#"id"];
NSMutableArray * shopArray = [[NSMutableArray alloc]initWithCapacity:100];
NSMutableDictionary * catDict = nil;
for (NSDictionary * dict in array) {
NSNumber * catID = [dict objectForKey:#"id"];
if ([lastID isEqualToNumber:catID]) {
[shopArray addObject:dict];
}
else {
catDict = [[NSMutableDictionary alloc]init ];
[catDict setObject:[shopArray copy] forKey:lastID];
[subcategorySplittedArray addObject:catDict];
[shopArray removeAllObjects];
[shopArray addObject:dict];
lastID = catID;
}
}
catDict = [[NSMutableDictionary alloc]init ];
[catDict setObject:[shopArray copy] forKey:lastID];
[subcategorySplittedArray addObject:catDict];
////////////////////////////////////
return subcategorySplittedArray;
}
NSMutableDictionary* result = [NSMutableDictionary dictionary];
NSArray* ids = [array valueWithKey:#"id"];
NSSet* uniqueIDs = [NSSet setWithArray:ids];
for (NSNumber* anID in uniqueIDs)
{
NSPredicate* pred = [NSPredicate predicateWithFormat:#"id == %#", anID];
NSArray* dictsForID = [array filteredArrayUsingPredicate:pred];
[result setObject:dictsForID forKey:anID];
}
If there are lots of IDs, you may be able to speed this up a bit by building a predicate with a variable reference outside of the loop and then just substituting the variable in to produce the id-specific predicate for each pass through the loop.
By the way, in your question, the result "field" is still an array for some reason. I don't think it needs to be.
Updated to make just one pass:
NSMutableDictionary* result = [NSMutableDictionary dictionary];
for (NSDictionary* dict in array)
{
NSNumber* anID = [dict objectForKey:#"id"];
NSMutableArray* resultsForID = [result objectForKey:anID];
if (!resultsForID)
{
resultsForID = [NSMutableArray array];
[result setObject:resultsForID forKey:anID];
}
[resultsForID addObject:dict];
}

Dictionary object won't predicate

I have a json object coming in as
{
"c_id": "261",
"customer_id": "178729",
"name": "Three, Test"
},
{
"c_id": "261",
"customer_id": "178727",
"name": "Two, Test"
},
{
"c_id": "261",
"customer_id": "178728",
"name": "Two, Test"
},
{
"c_id": "261",
"customer_id": "185186",
"name": "Valid, Another"
},
{
"c_id": "261",
"customer_id": "183889",
"name": "White, Betty"
}
However when this code processes
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSMutableArray *tempCustomers = [[NSMutableArray alloc] init];
for (NSDictionary *dict in [json objectForKey:#"data"]) {
NSLog(#"dict: %#", dict);
NSLog(#"name: %#", [dict objectForKey:#"name"]);
[tempCustomers addObject:dict];
}
self.customers = tempCustomers;
NSLog(#"Customers: %#",customers);
self.customerData = [self partitionObjects:[self customers] collationStringSelector:#selector(self)];
NSLog(#"CustomerData: %#",customerData);
-(NSArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector
{
UILocalizedIndexedCollation *collation = [UILocalizedIndexedCollation currentCollation];
NSInteger sectionCount = [[collation sectionTitles] count];
NSMutableArray *unsortedSections = [NSMutableArray arrayWithCapacity:sectionCount];
for (int i = 0; i < sectionCount; i++) {
[unsortedSections addObject:[NSMutableArray array]];
}
for (id object in array) {
NSInteger index = [collation sectionForObject:[object objectForKey:#"name"] collationStringSelector:selector];
[[unsortedSections objectAtIndex:index] addObject:object];
}
NSMutableArray *sections = [NSMutableArray arrayWithCapacity:sectionCount];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"name" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
for (NSMutableArray *section in unsortedSections) {
NSArray *sortedArray = [section sortedArrayUsingDescriptors:sortDescriptors];
//NSLog(#"Sort: %#",sortedArray);
//[sections addObject:[collation sortedArrayFromArray:section collationStringSelector:selector]];
[sections addObject:sortedArray];
}
return sections;
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
NSLog(#"Search Display Controller: %#", self.customerData);
//NSString *predicateString = [NSString stringWithFormat:#"name CONTAINS[cd] '%#'",searchString];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"name CONTAINS[cd] '%#'",searchString];
self.filteredCustomers = [[self.customerData filteredArrayUsingPredicate:predicate] mutableCopy];
NSLog(#"Filtered Customers %#", self.filteredCustomers);
return YES;
}
It shows
2012-03-26 14:15:21.885 MyApp[65799:15003] name: Two, Test
2012-03-26 14:15:21.885 MyApp[65799:15003] dict: {
"c_id" = 261;
"customer_id" = 178728;
name = "Two, Test";
}
2012-03-26 14:15:21.885 MyApp[65799:15003] name: Two, Test
2012-03-26 14:15:21.885 MyApp[65799:15003] dict: {
"c_id" = 261;
"customer_id" = 185186;
name = "Valid, Another";
}
2012-03-26 14:15:21.885 MyApp[65799:15003] name: Valid, Another
2012-03-26 14:15:21.886 MyApp[65799:15003] dict: {
"c_id" = 261;
"customer_id" = 183889;
name = "White, Betty";
}
2012-03-26 14:15:21.886 MyApp[65799:15003] name: White, Betty
2012-03-27 08:35:24.764 MyApp[67330:fb03] Search Display Controller: (
(
),
(
{
"c_id" = 261;
"customer_id" = 178664;
name = "Test, My";
},
{
"c_id" = 261;
"customer_id" = 185182;
name = "Test, valid";
},
{
"c_id" = 261;
"customer_id" = 178729;
name = "Three, Test";
},
{
"c_id" = 261;
"customer_id" = 178727;
name = "Two, Test";
},
{
"c_id" = 261;
"customer_id" = 178728;
name = "Two, Test";
}
),
(
),
(
{
"c_id" = 261;
"customer_id" = 185186;
name = "Valid, Another";
}
),
(
{
"c_id" = 261;
"customer_id" = 183889;
name = "White, Betty";
}
),
(
),
(
),
(
),
(
)
)
2012-03-27 08:35:24.766 MyApp[67330:fb03] Filtered Customers (
)
Notice the " " around the name key are missing. I believe this is why my NSPredicate in my searchDisplayController isn't working. Why are the quotes being removed and how would I fix my searchDisplayController to work?
I just noticed, in your predicate, you have single quotes around the %# -- they shouldn't be there. Putting the single quotes around %# turns it into a literal.

How do I parse JSON with Objective-C?

I am new to iPhone. Can anyone tell me the steps to follow to parse this data and get the activity details, first name, and last name?
{
"#error": false,
"#data": {
"": {
"activity_id": "35336",
"user_id": "1",
"user_first_name": "Chandra Bhusan",
"user_last_name": "Pandey",
"time": "1300870420",
"activity_details": "Good\n",
"activity_type": "status_update",
"photo_url": "http://184.73.155.44/hcl-meme/QA_TEST/sites/default/files/pictures/picture-1627435117.jpg"
},
"boolean": "1",
"1": {
"1": {
"photo_1_id": "9755"
},
"activity_id": "35294",
"album_name": "Kalai_new_Gallery",
"user_id": "31",
"album_id": "9754",
"user_first_name": "Kalaiyarasan",
"user_last_name": "Balu",
"0": {
"photo_0_id": "9756"
},
"time": "1300365758",
"activity_type": "photo_upload",
"photo_url": "http://184.73.155.44/hcl-meme/QA_TEST/"
},
"3": {
"activity_id": "35289",
"user_id": "33",
"user_first_name": "Girija",
"user_last_name": "S",
"time": "1300279636",
"activity_details": "girija Again\n",
"activity_type": "status_update",
"photo_url": "http://184.73.155.44/hcl-meme/QA_TEST/sites/default/files/pictures/picture-33-6361851323080768.jpg"
},
"2": {
"owner_first_name": "Girija",
"activity_id": "35290",
"activity_details": "a:2:{s:4:\"html\";s:51:\"!user_fullname and !friend_fullname are now friends\";s:4:\"type\";s:10:\"friend_add\";}",
"activity_type": "friend accept",
"owner_last_name": "S",
"time": "1300280400",
"photo_url": "http://184.73.155.44/hcl-meme/QA_TEST/sites/default/files/pictures/picture-33-6361851323080768.jpg",
"owner_id": "33"
},
"4": {
"activity_id": "35288",
"user_id": "33",
"user_first_name": "Girija",
"user_last_name": "S",
"time": "1300279530",
"activity_details": "girija from mobile\n",
"activity_type": "status_update",
"photo_url": "http://184.73.155.44/hcl-meme/QA_TEST/sites/default/files/pictures/picture-33-6361851323080768.jpg"
}
}
}
With the perspective of the OS X v10.7 and iOS 5 launches, probably the first thing to recommend now is NSJSONSerialization, Apple's supplied JSON parser. Use third-party options only as a fallback if you find that class unavailable at runtime.
So, for example:
NSData *returnedData = ...JSON data, probably from a web request...
// probably check here that returnedData isn't nil; attempting
// NSJSONSerialization with nil data raises an exception, and who
// knows how your third-party library intends to react?
if(NSClassFromString(#"NSJSONSerialization"))
{
NSError *error = nil;
id object = [NSJSONSerialization
JSONObjectWithData:returnedData
options:0
error:&error];
if(error) { /* JSON was malformed, act appropriately here */ }
// the originating poster wants to deal with dictionaries;
// assuming you do too then something like this is the first
// validation step:
if([object isKindOfClass:[NSDictionary class]])
{
NSDictionary *results = object;
/* proceed with results as you like; the assignment to
an explicit NSDictionary * is artificial step to get
compile-time checking from here on down (and better autocompletion
when editing). You could have just made object an NSDictionary *
in the first place but stylistically you might prefer to keep
the question of type open until it's confirmed */
}
else
{
/* there's no guarantee that the outermost object in a JSON
packet will be a dictionary; if we get here then it wasn't,
so 'object' shouldn't be treated as an NSDictionary; probably
you need to report a suitable error condition */
}
}
else
{
// the user is using iOS 4; we'll need to use a third-party solution.
// If you don't intend to support iOS 4 then get rid of this entire
// conditional and just jump straight to
// NSError *error = nil;
// [NSJSONSerialization JSONObjectWithData:...
}
Don't reinvent the wheel. Use json-framework or something similar.
If you do decide to use json-framework, here's how you would parse a JSON string into an NSDictionary:
SBJsonParser* parser = [[[SBJsonParser alloc] init] autorelease];
// assuming jsonString is your JSON string...
NSDictionary* myDict = [parser objectWithString:jsonString];
// now you can grab data out of the dictionary using objectForKey or another dictionary method
NSString* path = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"json"];
//将文件内容读取到字符串中,注意编码NSUTF8StringEncoding 防止乱码,
NSString* jsonString = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//将字符串写到缓冲区。
NSData* jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *jsonError;
id allKeys = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONWritingPrettyPrinted error:&jsonError];
for (int i=0; i<[allKeys count]; i++) {
NSDictionary *arrayResult = [allKeys objectAtIndex:i];
NSLog(#"name=%#",[arrayResult objectForKey:#"storyboardName"]);
}
file:
[
{
"ID":1,
"idSort" : 0,
"deleted":0,
"storyboardName" : "MLMember",
"dispalyTitle" : "76.360779",
"rightLevel" : "10.010490",
"showTabBar" : 1,
"openWeb" : 0,
"webUrl":""
},
{
"ID":1,
"idSort" : 0,
"deleted":0,
"storyboardName" : "0.00",
"dispalyTitle" : "76.360779",
"rightLevel" : "10.010490",
"showTabBar" : 1,
"openWeb" : 0,
"webUrl":""
}
]
JSON parsing using NSJSONSerialization
NSString* path = [[NSBundle mainBundle] pathForResource:#"data" ofType:#"json"];
//Here you can take JSON string from your URL ,I am using json file
NSString* jsonString = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSData* jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *jsonError;
NSArray *jsonDataArray = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&jsonError];
NSLog(#"jsonDataArray: %#",jsonDataArray);
NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&jsonError];
if(jsonObject !=nil){
// NSString *errorCode=[NSMutableString stringWithFormat:#"%#",[jsonObject objectForKey:#"response"]];
if(![[jsonObject objectForKey:#"#data"] isEqual:#""]){
NSMutableArray *array=[jsonObject objectForKey:#"#data"];
// NSLog(#"array: %#",array);
NSLog(#"array: %d",array.count);
int k = 0;
for(int z = 0; z<array.count;z++){
NSString *strfd = [NSString stringWithFormat:#"%d",k];
NSDictionary *dicr = jsonObject[#"#data"][strfd];
k=k+1;
// NSLog(#"dicr: %#",dicr);
NSLog(#"Firstname - Lastname : %# - %#",
[NSMutableString stringWithFormat:#"%#",[dicr objectForKey:#"user_first_name"]],
[NSMutableString stringWithFormat:#"%#",[dicr objectForKey:#"user_last_name"]]);
}
}
}
You can see the Console output as below :
Firstname - Lastname : Chandra Bhusan - Pandey
Firstname - Lastname : Kalaiyarasan - Balu
Firstname - Lastname : (null) - (null)
Firstname - Lastname : Girija - S
Firstname - Lastname : Girija - S
Firstname - Lastname : (null) - (null)
I recommend and use TouchJSON for parsing JSON.
To answer your comment to Alex. Here's quick code that should allow you to get the fields like activity_details, last_name, etc. from the json dictionary that is returned:
NSDictionary *userinfo=[jsondic valueforKey:#"#data"];
NSDictionary *user;
NSInteger i = 0;
NSString *skey;
if(userinfo != nil){
for( i = 0; i < [userinfo count]; i++ ) {
if(i)
skey = [NSString stringWithFormat:#"%d",i];
else
skey = #"";
user = [userinfo objectForKey:skey];
NSLog(#"activity_details:%#",[user objectForKey:#"activity_details"]);
NSLog(#"last_name:%#",[user objectForKey:#"last_name"]);
NSLog(#"first_name:%#",[user objectForKey:#"first_name"]);
NSLog(#"photo_url:%#",[user objectForKey:#"photo_url"]);
}
}