2つのセクションがあり、各セクションには約10〜17個の質問があります。 json apiを使用してサーバーに回答を投稿すると、 の結果がunorderlist 、 私の質問は、 "Index_id"で "Question_id"をサーバから受信して表示する方法です。インデックス値を順序付きリストと値で表示する方法
- (IBAction)Submit:(id)sender
{
AppDelegate *apd = [[UIApplication sharedApplication] delegate];
NSUInteger arrayCount;
NSMutableDictionary *question_array = [[NSMutableDictionary alloc]init];
int k = 0;
for (int i=0; i<dicc.count; i++) {
NSMutableDictionary *answerDict = [[NSMutableDictionary alloc]init];
arrayCount = [[dicc valueForKey:[headersArray objectAtIndex:i]]count];
for (int j=0; j<arrayCount; j++)
{
int x = k + j;
NSString *key = [NSString stringWithFormat:@"%d", j];
answerDict[key] = take_five_ans_arr[x];
}
// NSString * key = [[dicc valueForKey:[headersArray objectAtIndex:i]]valueForKey:@"question_id"]; // get question id
NSString *key = [NSString stringWithFormat:@"%d", i];
question_array[key] = answerDict;
k += arrayCount;
}
NSString *post = [NSString stringWithFormat:@"jobid=%@&id=%@&questionarray=%@",apd.jobid2,user_idis,question_array];
NSLog(@"%@",post);
// NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://10.10.1.13//webservices_api/process"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(conn)
{
NSLog(@"Connection Successful");
}
else
{
NSLog(@"Connection could not be made");
}
}
私は取得しています出力は次のようになります。
questionarray=
{
0 = {
0 = 1;
1 = 1;
10 = 1;
11 = 1;
12 = 1;
13 = 1;
14 = 1;
15 = 1;
16 = 1;
2 = 1;
3 = 1;
4 = 1;
5 = 1;
6 = 1;
7 = 1;
8 = 1;
9 = 1;
};
1 = {
0 = 0;
1 = 0;
10 = 0;
11 = 0;
12 = 0;
13 = 0;
14 = 0;
15 = 0;
2 = 0;
3 = 0;
4 = 0;
5 = 0;
6 = 0;
7 = 0;
8 = 0;
9 = 0;
};
しかし、私はAPIからフェッチされる "Question_id" をindexrowid表示したい、 私のJSON APIは次のとおりです。
{"question_id":"27","question_title":"Do I need mechanical lifting or a work at height platform? .. ","question_answer":"No","question_type":"Full"}
ますので、答えは右の前に、質問IDを渡す必要がありますか? – Purushothaman
はい、インデックスIDも@Purushothaman –