Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to cut the json field values & store it in different indexes

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

Out Put:-

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

I have this type of data in the json parsing field "desc".

This data has some "|" & ";" separated values.

from this kind of data I want to store the data in two different parameters like...

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

Home               2028

Services           2029

Clients            2030

Portfolio          2031

Company            2032

Contact Us         2033

Career             2034
like image 714
Jignesh Fadadu Avatar asked Nov 04 '22 20:11

Jignesh Fadadu


1 Answers

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

try it.. vipul patel

like image 141
Victor Avatar answered Nov 15 '22 04:11

Victor