gpt4 book ai didi

iphone - 如何切割json字段值并将其存储在不同的索引中

转载 作者:可可西里 更新时间:2023-11-01 04:48:11 25 4
gpt4 key购买 nike

desc = [[NSMutableArray alloc] init];
for (NSString * strName in results)
{
arrRates = [results objectForKey:strName];
for (int i = 0; i <= [arrRates count]; i++)
{
if ([[[arrRates objectAtIndex:i] valueForKey:@"type"] isEqualToString:@"0"])
{
nextUrl = [[arrRates objectAtIndex:i] valueForKey:@"Nexturl"];
[desc addObject:[[arrRates objectAtIndex:i] valueForKey:@"desc"]];
}
}
}
NSLog(@"type 0 desc is:--> %@",desc);

输出:-

[7666:b303] type 0 desc is:--> (
"Home|2028;Services|2029;Clients|2030;Portfolio|2031;Company|2032;Contact Us|2033;Career|2034;",
"Article Submission|2064;Social Bookmarking|2065;Directory Submission|2066;Forum / Blog Link Generation|2067;Press Release Distribution|2068;Link Wheel Creation|2069;Content Writing|2070;Video Marketing|2071;",
"Magento|2072;Joomla|2073;Wordpress|2074;Drupal|2075;osCommerce / Zencart|2076;",
"PSD to XHTML|2077;Newsletter Design|2078;Logo Design|2079;Website Redesign|2080;W3C Validation|2081;Flash Intro|2082;",
"SEO Services|2035;BPO / KPO Services|2036;Web Development|2037;Mobile Apps.|2038;",
"SEO Portfolio|2039;Web Development Portfolio|2040;",
"About Elsner|2083;Vision, Mission, Values|2084;Leadership Team|2085;Our Partners|2086;Awards and Recognition|2087;Press|2088;Events|2089;",
"Link Building Services|2041;Pay Per Click Marketing Services|2042;Search Engine Marketing|2043;Social Media Marketing|2044;Keyword Research|2045;Website Optimization|2046;",
"Data Entry Services|2048;Live Chat Support|2049;B2B Lead Generation|2050;24 x 7 Technical Support|2051;HR Recruitment Service|2052;Market Research and Analysis |2053;",
"Open Source Solution|2054;Custom PHP|2055;CRM|2056;Ecommerce Solution|2057;Website Design|2058;Website Design|2058;Website Design|2059;",
"Blackberry Apps|2060;J2ME Apps|2061;Iphone Apps|2062;Android Apps|2063;"
)

我在json解析字段"desc"中有这种类型的数据。

这个数据有一些“|” & ";"分隔值。

对于这种数据,我想将数据存储在两个不同的参数中,例如...

title              id
------- ----

Home 2028

Services 2029

Clients 2030

Portfolio 2031

Company 2032

Contact Us 2033

Career 2034

最佳答案

  NSString *desc=@"Home|2028;Services|2029;Clients|2030;Portfolio|2031";
NSArray *arr=[desc componentsSeparatedByString:@";"];
NSString *sub=@"|";
NSMutableArray *arrTitle=[[NSMutableArray alloc]init];
NSMutableArray *arrId=[[NSMutableArray alloc]init];
for (int i=0; i<[arr count]; i++) {
[arrTitle addObject:[[arr objectAtIndex:i] substringToIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:sub])-1]];
[arrId addObject:[[arr objectAtIndex:i] substringFromIndex:NSMaxRange([[arr objectAtIndex:i] rangeOfString:sub])]];
}

试一试.. vipul patel

关于iphone - 如何切割json字段值并将其存储在不同的索引中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11451648/

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