0

この行の実行時にJsonファイルを解析すると

model.userProfileObj.userFirstName = [NSString stringWithFormat:@"%@",[[responseDict valueForKey:@"Profile"] valueForKey:@"first_name"]];

Profile は私の辞書で、first_name はその内部変数です。お気に入り:

[
    {
        "Profile": {
            "id": "13",
            "user_id": "13",
            "first_name": "Myname",
            "profile_image": "13-IMG_169.png",
        }
    }
]

次の文字列を model.userProfileObj.userFirstName に割り当てますが、 MyName のみが必要であり、変数には ( と " は必要ありません。

(
    "Myname"
)
4

3 に答える 3

0

結果responseDictは配列形式であり、それを辞書として使用しているため、このような結果が得られます

(
    "Myname"
)

コードで1つのことを行うだけです..[responseDict objectAtIndex:0]

あなたのコード

model.userProfileObj.userFirstName = [NSString stringWithFormat:@"%@",[[[responseDict objectAtIndex:0] valueForKey:@"Profile"] valueForKey:@"first_name"]];
于 2012-11-27T13:39:04.047 に答える
0

JSONコンテンツを含む文字列がある場合、次のような正規表現を使用できます

 NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"Myname:\\\"([^\\\"]*)\\\"" options:0 error:NULL];
    NSTextCheckingResult *match = [regex firstMatchInString:apiResponse options:0 range:NSMakeRange(0, [apiResponse length])];

    NSString *encodedPoints = [jsonAsString substringWithRange:[match rangeAtIndex:1]];
于 2012-11-27T11:22:49.003 に答える
0
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSString *returnString=[[NSString alloc]initWithData:dataReceivedG encoding:NSASCIIStringEncoding];
    SBJSON *jsonParser=[[SBJSON alloc]init];
    NSDictionary *_dict=(NSDictionary *)[jsonParser objectWithString:returnString error:nil];
    NSLog(@"----%@",_dict);
    NSArray *_arrData=(NSArray *)[_dict ob
    //NSDictionary *_dictResponse=(NSDictionary *)[_objectForKey:@"profile"];
    NSLog(@"===%@",_arrData);
    for (int j=0; j<[_arrData count]; j++) 
    {
        [arrayListG addObject:[[_arrData objectAtIndex:j]valueForKey:@"first_name"]];
    }
} 

これをチェックして。

于 2012-11-27T11:08:01.953 に答える