2017-08-03 5 views
0

Betrachten Sie diese JSONNSManagedObject mit reaktiven Ziel c

“data” : [ { 
     - - - - - some user data - - - - - 
     “A” : [ { 
     - - - - A’s data - - — - - - - — - -  
       “a” : [ { 
     - - - - - a’s data - - - - - - - - - - 

    “ a1” : [ { 
     - - — - - b’s data — — — }] } } } ] ] ] 

Auf dieser Grundlage ich in einem Objekt zu überprüfen, müssen a1 ist oder nicht. Wenn a1 vorhanden ist, wird bedeutet, dass der Listener mithilfe von Reactive Objective-C aktualisiert wird. Kann mir bitte jemand dabei helfen?

Antwort

2

Verwenden Sie den folgenden Code. Hoffe, das hilft

/* 
    convert JSON to NSDictionary 
*/ 
NSDictionary *bodyDict = [utility convertStringToDictionary:jsonString]; 

if([bodyDict objectForKey:@“a1”]) 
{ 
    //Post your listener notification 
} 

-Code-String zu NSDictionary zu konvertieren

-(NSDictionary *)convertStringToDictionary:(NSString *)jsonString{ 

    NSError * err; 
    NSData *data =[jsonString dataUsingEncoding:NSUTF8StringEncoding]; 
    NSDictionary * response = nil; 

    if(data!=nil){ 
     response = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&err]; 
    } 

    return response; 
} 
2

die nur a1 Werte in Json Daten. Verwenden Sie die folgende Zeile, um a1 Werte sind in Json oder nicht,

NSMutableArray *Arr = [[NSMutableArray alloc] init]; 
Arr = [JsonData valueForKeyPath:@"data.A.a.a1"]; 

if(Arr.count == 0) NSLog(@"Update : YES"); 
else NSLog(@"Update : NO");