2017-04-15 3 views
0

この解析結果から日付と単独のタイトルや説明を取得する方法:同じAPIが異なるから解析を(だこの解析結果から日付と単独のタイトルと説明を取得する方法

title = "Inter-views 29/03/2017 random description here (its in arabic); 
title = " \U0627\U062e\U0628\U0627\U0631 \U0627\U0644\U0635\U0628\U0627\U062d 14/04/2017"; 

didSelectRowAtIndexPath)。 私は現在このコードを使用していますが、私が通知したとおり、解析は異なります。だから私は静的ロジックを使用することはできません。

コード:

NSString *myString = [item objectForKey:@"title"]; 

    NSMutableArray *myArray = [[NSMutableArray alloc] 
    initWithArray:[myString componentsSeparatedByCharactersInSet: 
    [NSCharacterSet characterSetWithCharactersInString:@" "]]]; 

     NSString *Category = @""; 
     if(myArray.count>=1){ 
      Category = [myArray objectAtIndex:0]; 
      [myArray removeObjectAtIndex:0]; 
     } 
     NSString *Date = @""; 
     if(myArray.count>=1) { 
      Date = [myArray objectAtIndex:0]; 
      [myArray removeObjectAtIndex:0]; 
     } 
     cell.dateLabel.text = [[NSString alloc] initWithFormat:@"%@", [Utils dateTransform:[Date stringByReplacingOccurrencesOfString:@" " withString:@""] FromFormat:@"dd-MM-yyyy" ToFormat:@"dd-MMMM-yyyy"]]; 
     NSString *Title = @""; 
     for (NSString *word in myArray) { 
      Title = [Title stringByAppendingString:word]; 
      Title = [Title stringByAppendingString:@" "]; 
     } 
     cell.titleAndDescLabel.text =[NSString stringWithFormat:@"%@ %@", Category,Title]; 
+0

を取得するために、forループを使用する必要がありますか? Webサービスから?サーバーからデータを取得した場合は、私に返信してください。 –

+0

@DishantRajputそれはレスポンスだけど、私はそれが他のものと違うと言ったから :id = 3502; image = ""; isYoutube = 1; link = "https://youtu.be/a_AnoV3y1EM"; タイトル=「インタービュー29/03/2017 \ U0645 \ U0639 \ U0623 \ U0648 \ U0644 \ U0648 \ U0632 \ U064a \ U0631 \ U062f \ U0 }とthatsの別の応答: ID = 3432; イメージ= ""; isYoutube = 1; リンク= "https://youtu.be/bSds01Ew6ns"; タイトル= "インタビュー22/03/2017"; } – Baloomba

+0

私の回答を確認してください。あなたの価値を一つ一つ手に入れるためにはforループを使わなければなりません。 –

答えて

0

あなたの価値、あなたのデータを取得する方法

for (NSInteger i=0; i<[[jsonObject objectForKey:@"yourMainKey"]count]; i++) 
      { 

NSString *strname =[[[jsonObject objectForKey:@"yourMainKey"]objectAtIndex:i]objectForKey:@"date"]; 

       NSLog(@"strname==%@, strname); 


NSString *str title =[[[jsonObject objectForKey:@"yourMainKey"]objectAtIndex:i]objectForKey:@"title"]; 

       NSLog(@"strtitle ==%@, strtitle); 

NSString *str description =[[[jsonObject objectForKey:@"yourMainKey"]objectAtIndex:i]objectForKey:@"description"]; 

       NSLog(@"description ==%@, description); 



      } 
関連する問題