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 に答える