问题
So I am building an app that uses parse as a backend. I've written my own before but I figured I'll just save some time and use parse. I'm populating a table view with data from parse and that's fine. I want to grab the objectId from an dictionary built from an array from parse.
The output of my array is as follows:
<news_events:pdbIEvOteH:(null)> {\n eventDescription = \"This is a test description.\";\n eventMessage = \"This is a test message.\";\n eventTitle = \"Free Wi-Fi Now Available!\";\n}
The object ID is pdbIEvOteH
in the example above. I at first tried getting the id by using:
NSString * objectId = [myDictionary objectForKey:@"objectId"];
But that returned null. I know it is not a problem with my dictionary because I can get other information. The problem is it looks like there is no key for objectId
in the array above. As you can see it follows news_events
.
I know you can get it with the PFObject
but I'm not sure if I can populate a table with a PFObject
.
So bottom line is how do I get the objectId
.
回答1:
In my didSelectRowAtIndexPath:
method, I did the following:
PFObject *myObject = [parseArray objectAtIndex:indexPath.row];
NSString *objectId = [myObject objectId];
回答2:
To get the Id of a particular PFObject.
In Swift:
var objectId = object.objectId
In Objective-C:
NSString *objectId = object.objectId;
回答3:
"So bottom line is how do I get the objectId."
following is answer from 'Joe Blow' with actual/example code for ios.
i had similar issue. retrieving data with following code worked:
NSString *reporterOpinion = [NSString stringWithFormat:@"%@", [object objectForKey:@"reporterOpinion"]];
but trying to do objectForKey with objectId returned null:
NSString *objectId = [NSString stringWithFormat:@"%@", [object objectForKey:@"objectId]];
following 'Joe Blow' answer, the following code returned correct value for objectId:
NSString *objectId = object.objectId;
来源:https://stackoverflow.com/questions/18341035/getting-objectid-from-parse-com