2

这是我获取json响应字符串的代码

我通过使用这种方法得到这个字符串

NSDictionary *selector = [json valueForKey: @"Title"];
NSMutableArray *dictArray = [[NSMutableArray alloc] initWithObjects: selector,nil];
str1=[[dictArray objectAtIndex:i] valueForKey:@"CompanyName"];

打印“str1”

我正进入(状态

(
    "hello@developer.com"
),
    (
    "hello@developer.com",
    "helloworld@microsoft.com"
),
    (
    "hello@developer.com"
),
    (
    "hello@developer.com"
),
    (
    "hello@developer.com"
),
    (
    "hello@developer.com"
),
    (
    "hello@developer.com"
),
    (
    "hello@developer.com"
)

)

我正在尝试使用“,”运算符存储在数组中

像这样

NSArray *SplitStringArray = [str1 componentsSeparatedByString:@", "];

但我没有将字符串拆分为元素数组

可以请任何人帮助我吗?

4

2 回答 2

1
    NSDictionary *selector = [json valueForKey: @"Title"];

    NSMutableArray *dictArray = [[NSMutableArray alloc] initWithObjects: selector,nil];

    NSMutableArray *str1Array=[[dictArray objectAtIndex:i] valueForKey:@"CompanyName"];


        //note this line
    NSMutableArray *SplitStringArray =[[NSMutableArray alloc]init];

    for (id eachArray in str1Array) {


        if ([eachArray count]>0) {


            for (int i = 0; i<[eachArray count]; i++) {

                NSString *emailid=[NSString stringWithFormat:@"%@",[eachArray objectAtIndex:i]];

                [SplitStringArray addObject:emailid];


            }

        }

    }

    NSLog(@"SplitStringArray : %@",SplitStringArray);
于 2012-05-23T11:55:02.987 回答
1
NSMutableArray *SplitStringArray = [[NSMutableArray alloc]init]; 
[SplitStringArray setArray:[str1 componentsSeparatedByString:@","]];
于 2012-05-23T11:58:03.020 回答