2016-07-16 3 views
-1

は、これが私のNSMutableArrayの形式であり、これは正常に動作しているともNSMutableArrayでNSPredicateコードがクラッシュするObjective Cの

[ 
    { 
     "status":"not completed", 
     "rating":2 
    },{ 
     "status":"completed", 
     "rating":2 
    },{ 
     "status":"not completed", 
     "rating":"<null>" 
    },{ 
     "status":"completed", 
     "rating":"<null>" 
    },{ 
     "status":"not completed", 
     "rating":"<null>" 
    } 
] 

を正しい応答を取得していますし、コードが

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self.status == 'completed' and self.rating == NULL"]; 

NSArray *arr = [order filteredArrayUsingPredicate:predicate]; 

であるが、いくつかのケースで私NSMutableArrayのは、このフォームに変更されることがあり

[ 
    { 
     "status":not completed, 
     "rating":2 
    },{ 
     "status":not completed, 
     "rating":2 
    },{ 
     "status":not completed, 
     "rating":4 
    } 
] 

ここでコードがクラッシュする

NSArray *arr = [order filteredArrayUsingPredicate:predicate]; 

私はここでコンソール画面添付した

クラッシュ

それはNSDictionary *jorder = response; iがNSMutableArray *jorder = response;

enter image description here

クラッシュにこれを変換する述語を使用していた前に、コードのよう に誤りがありましたと言う。

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary filteredArrayUsingPredicate:]: unrecognized selector sent to instance 0x13f209b60' 
*** First throw call stack: 
(0x1841e6db0 0x18384bf80 0x1841edc4c 0x1841eabec 0x1840e8c5c 0x1001354ac 0x100135278 0x1000aaf4c 0x1001549cc 0x100e55a7c 0x100e55a3c 0x100e5b4e4 0x18419cd50 0x18419abb8 0x1840c4c50 0x1859ac088 0x1893ae088 0x100125798 0x183c628b8) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
+0

細かい作業になります。このrating.lengthを試す<= 0 ...代わりにNULLでそれを確認します。 – commando24

+0

私の答えをチェックしてください。 –

+0

'NULL'の代わりに 'nil'を使用してください。 –

答えて

0

plzはこのコードを使用

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self.status == 'completed' AND self.rating == %@",@"<null>"]; 

NSArray *arr = [order filteredArrayUsingPredicate:predicate]; 

結果

enter image description here

私のデバッグで

そのショーの結果 enter image description here

+0

PLSは再び – Bangalore

+0

は私の更新の答えを参照してくださいクラッシュの他の理由がなければならない@Bangalore qstn読み@kaushal –

+0

あなたは私の質問をチェックしていない、男私はこれらの[ を持っています{ "ステータス": "完了していない"、 "評価":2 }、{ "ステータス": "完了していない"、 "評価":2 }、{ "ステータス" が "完了していません" 、 "rating":4 } ]私はこの投稿をお待ちしています。 – Bangalore

0

このコードに

NSString *[email protected]"[{\"status\":\"not completed\",\"rating\":2},{\"status\":\"not completed\",\"rating\":2},{\"status\":\"not completed\",\"rating\":2},{\"status\":\"not completed\",\"rating\":2},{\"status\":\"not completed\",\"rating\":2}]"; 
    NSData *data=[response dataUsingEncoding:NSUTF8StringEncoding]; 
    NSMutableArray *array=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil]; 
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self.status == 'completed' AND self.rating == %@",@"<null>"]; 

    NSArray *arr = [array filteredArrayUsingPredicate:predicate]; 
をご確認ください。

と配列がある

<__NSCFArray 0x7f880a5eda70>(
{ 
    rating = 2; 
    status = "not completed"; 
}, 
{ 
    rating = 2; 
    status = "not completed"; 
}, 
{ 
    rating = 2; 
    status = "not completed"; 
}, 
{ 
    rating = 2; 
    status = "not completed"; 
}, 
{ 
    rating = 2; 
    status = "not completed"; 
} 
) 

それは

関連する問題