简体   繁体   English

从parse.com获取objectId

[英]Getting objectId from parse.com

So I am building an app that uses parse as a backend. 所以我正在构建一个使用parse作为后端的应用程序。 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. 我想从一个从解析数组构建的字典中获取objectId。

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. 在上面的示例中,对象ID是pdbIEvOteH I at first tried getting the id by using: NSString * objectId = [myDictionary objectForKey:@"objectId"]; 我首先尝试使用: NSString * objectId = [myDictionary objectForKey:@"objectId"]; But that returned null. 但那返回了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. 问题是看起来上面的数组中没有objectId键。 As you can see it follows news_events . 正如您所看到的,它遵循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 . 我知道你可以用PFObject获得它,但我不确定我是否可以使用PFObject填充表。

So bottom line is how do I get the objectId . 所以底线是我如何得到objectId

In my didSelectRowAtIndexPath: method, I did the following: 在我的didSelectRowAtIndexPath:方法中,我执行了以下操作:

PFObject *myObject = [parseArray objectAtIndex:indexPath.row];

NSString *objectId = [myObject objectId];

To get the Id of a particular PFObject. 获取特定PFObject的Id。

In Swift: 在Swift中:

var objectId = object.objectId

In Objective-C: 在Objective-C中:

NSString *objectId = object.objectId;

"So bottom line is how do I get the objectId." “所以底线是我如何得到objectId。”

following is answer from 'Joe Blow' with actual/example code for ios. 以下是来自'Joe Blow'的回答,其中包含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: 但尝试使用objectId执行objectForKey返回null:

NSString *objectId = [NSString stringWithFormat:@"%@", [object objectForKey:@"objectId]];

following 'Joe Blow' answer, the following code returned correct value for objectId: 在'Joe Blow'回答后,以下代码返回了objectId的正确值:

NSString *objectId = object.objectId;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM