gpt4 book ai didi

objective-c - 如何从这个解析结果中单独获取日期和标题和描述

转载 作者:行者123 更新时间:2023-11-30 12:31:56 25 4
gpt4 key购买 nike

如何从解析结果中单独获取日期、标题和描述:

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";

这是来自相同 api 但不同的解析 (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];

最佳答案

你必须使用for循环来获取值(value)

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);



}

关于objective-c - 如何从这个解析结果中单独获取日期和标题和描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43421007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com