function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
maceWindumaceWindu 

Issues with JSON in the IOS SDK.

if I do  a query such as this 

SELECT (SELECT Name FROM Opportunities) FROM Account in the IOS SDK ... I get a result of this:

Records (

        {

        Opportunities =         {

            done = 1;

            records =             (

                                {

                    Name = "GenePoint SLA";

                    attributes = {

                        type = Opportunity;

                        url = "/services/data/v23.0/sobjects/Opportunity/006A0000002E7YzIAK";

                    };

 

                },

                                {

                    Name = "GenePoint Lab Generators";

                    attributes =                     {

                        type = Opportunity;

                        url = "/services/data/v23.0/sobjects/Opportunity/006A0000002E7YyIAK";

                    };

                },

                                {

                    Name = "GenePoint Standby Generator";

                    attributes =                     {

                        type = Opportunity;

                        url = "/services/data/v23.0/sobjects/Opportunity/006A0000002E7YqIAK";

                    };

                }

            );

            totalSize = 3;

        };

        attributes =         {

            type = Account;

            url = "/services/data/v23.0/sobjects/Account/001A0000002SbaDIAS";

        };

    },

        {

        Opportunities =         {

            done = 1;

            records =             (

                                {

                    Name = "Test OPP";

                    attributes =                     {

                        type = Opportunity;

                        url = "/services/data/v23.0/sobjects/Opportunity/006G000000IgoBuIAJ";

                    };

                }

            );

            totalSize = 1;

        };

        attributes =         {

            type = Account;

            url = "/services/data/v23.0/sobjects/Account/001A0000002SbaEIAS";

        };

    },

 

It comes up blank but I'm not sure why.

 

The sample code has this : 

// Configure the cell to show the data.

NSDictionary *obj = [dataRows objectAtIndex:indexPath.row];

    cell.textLabel.text =  [obj objectForKey:@"Name"];

in cellForRowAtIndexPath method. I've google it a couple of hours and becasue it seems like its more of a IOS thing rather than salesforce. But maybe someone has tried to do this and solved the issue I'm having. 

 

 

 

jhersh1jhersh1

That's a subquery, so the API returns a nested dictionary. Looks like you're not parsing that properly. 

 

You want something more akin to [[myRecords valueForKeyPath:@"Opportunities.records"] objectAtIndex:0], which ought to get you the first oppty in that subquery.

maceWindumaceWindu

Well i have tried so many things to get this work that I can't keep track of them all. 

 

 

 MY   SFRestRequest *request = [[SFRestAPIsharedInstance] requestForQuery:@"SELECT (SELECT Name FROM Opportunities) FROM Account"];    


 

here is the latest. 

 

// Configure the cell to show the data.

 

in the 

- (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath:(NSIndexPath *)indexPath {} method 

 

NSDictionary *obj =[[dataRows  valueForKeyPath:@"Opportunities.records"] objectAtIndex:0];

 

    for(NSString *s in [obj valueForKey:@"Name"]){

        cell.textLabel.text =s;

 

        NSLog(@"%@",s);


    

    }

 

 

 

and the only thing I get is the following, 

SFMobileApp[3389:fb03] GenePoint SLA

 SFMobilApp[3389:fb03] GenePoint Lab Generators

 SFMobileApp[3389:fb03] GenePoint Standby Generator

 

in the UITableView I get  GenePoint Standby Generator repeated and nothing else. 

 

Can someone help me with this?

 


jhersh1jhersh1

Not much to go on here :/ Are you displaying the proper number of rows? Are you constructing and reusing your cells properly?

 

Apple has extensive docs with lots of example projects, on UITableView and many others: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html

Gaurav KheterpalGaurav Kheterpal

+1 - the problem is in the way you are rendering the data. Your logs suggest that you are getting the data correctly.

 

You need to understand that ʺcellForRowAtIndexʺ delegate is called for every cell and you need not set text for all cells at once using a for loop. I think you need to get the right cell index to resolve the issue.

 

I hope that helps.

 

Regards,
Gaurav

maceWindumaceWindu

I know that cellForRowAtIndex is called for every cell. The for loop was just one of the things that i tried. I was able to get one value to show in the UITableView but not all of them.  To be honest I lost count how many different things I tried to make this work. I'm surprised that others have not run into the same issue when trying to parse nested JSON objects in ObjectiveC. I googled it but I nothing worked. I decided to change the query for data. 

 

So Instead of ...

SELECT (SELECT Name FROM Opportunities) FROM Account Where Name='GenePoint'

 

I just changed it to...

SELECT o.Name From Opportunity o WHERE Account.Name='GenePoint'

 

 

then I can keep it simple inside the cellForRowAtIndex method. 

// Configure the cell to show the data.

NSDictionary *obj = [dataRows objectAtIndex:indexPath.row];

 

cell.textLabel.text = [obj objectForKey:@"Name"];