The NSLOG of this object is :
(entity: Article; id: 0xd000000001440000 ; data: { email = "XXX@YYY.com"; name = "XXX"; })
I want to get name and email from it.
Asked
Active
Viewed 500 times
-3

vib
- 2,254
- 2
- 18
- 36

user3807662
- 1
- 3
-
You could convert it to NSString and then parse it as such. For conversion check here: http://stackoverflow.com/a/2467856/653513 – Rok Jarc May 21 '15 at 09:14
-
But its of id type not NSData. I must have done this using id type. Any other idea. Thank you – user3807662 May 21 '15 at 09:21
-
@user3807662 please read a basic Objective-C tutorial. You don't seem to know what types mean in Objective-C nor how they work. – The Paramagnetic Croissant May 21 '15 at 09:33
-
Where did this object come from? Is there any documentation you can look at? – Steve Ives May 21 '15 at 09:51
-
@user3807662: as Steve Ives said: if you can tell some more about this object you can get a more elegant solution. But if in hurry and all you need is find a way to get your data then you can convert it to string using code below (after edit...). – Rok Jarc May 21 '15 at 10:06
2 Answers
1
The simplest but most error-prone solution is to try
id email = [obj valueForKey:@"email"];
id name = [obj valueForKey:@"name"];
However this is error prone. For instance, the email could be a string value, or it could also be a wrapper email object.
If you do not have access to this data in the form of public API, you either need to change the library you are using, or find the method to extract this data properly.

Léo Natan
- 56,823
- 9
- 150
- 195
0
id yourObject = ...;
if ([yourObject conformsToProtocol:@protocol(NSCoding)])
{
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:yourObject];
NSString *strRepresentation = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSLog(@"We have payload: %@",strRepresentation);
}
EDIT:
There is another way. According to NSLog
of your object this should work:
NSString *strRepresentation = [NSString stringWithFormat:@"%@",yourObject];
And parse...

Rok Jarc
- 18,765
- 9
- 69
- 124