문제

I have created an NSDictionary named "myData" which contains the following JSON response:

{
listInfo =     (              
{ 
    date = 1392157366000;       
    dateAsString = "02/11/2014 22:22:46";     
    id = 6;  
    address = 542160e0000c;     
    myLevel = 13;  
},            
{

    date = 1392155568000;        
    dateAsString = "02/11/2014 21:52:48";      
    id = 5;    
    address = 542160e0000c;     
    myLevel = 13;

}
    );
}

I need to retrieve each of the [dateAsString] key/value pairs. I've tried: NSString *dateAsString=[[myData valueForKeyPath:@"dateAsString"][0] objectForKey:@"myData"]; without any luck.

Any suggestions are greatly appreciated.

도움이 되었습니까?

해결책

I think this will work:

NSArray* dateStringArray = [listInfo valueForKeyPath:@"@unionOfObjects.dateAsString"]

I believe it will give you an array of strings. If you need to stuff that back in a dictionary, that should be fairly easy.

It's not clear what your "myData" looks like... so I used the listInfo array of dicts shown.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top