mani chandran mani chandran - 23 days ago 6
iOS Question

How to display the index values in ordered list and with Values

i have two sections and each section conatin around 10 to 17 questions ,
When i am posting the answers to the server using json api,
the result is displaying in unorderlist ,
my question is How to display in "Index_id" with "Question_id" which is coming from server.

- (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");
}
}


The output I am getting is:

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


But I want to display indexrowid "Question_id" which is to be fetch from api,
my Json api is :

{"question_id":"27","question_title":"Do I need mechanical lifting or a work at height platform? .. ","question_answer":"No","question_type":"Full"}

Answer

Now take one mutable array and initialise that , after that fetch the question id from the json data and then place before the index numbers.

    NSUInteger arrayCount;
    
    NSMutableArray * qid = [[NSMutableArray alloc] init];
    
    NSMutableDictionary *question_array = [[NSMutableDictionary alloc]init];

    int k = 0;
    
    for (int i=0; i<dicc.count; i++) {
        
 qid = [[dicc valueForKey:[headersArray objectAtIndex:i]]valueForKey:@"question_id"];

        NSMutableDictionary *answerDict = [[NSMutableDictionary alloc]init];
        
        arrayCount =  [[dicc valueForKey:[headersArray objectAtIndex:i]]count];
        
        for (int j=0; j<arrayCount; j++)
        {
            int x = k + j;
            
             NSString * key1 = [[dicc valueForKey:[headersArray objectAtIndex:i]]valueForKey:@"question_id"];

          NSString *key = [NSString stringWithFormat:@"%d, %@", j,qid[j]];
            
            answerDict[key] =  take_five_ans_arr[x];
        }

NSString *key = [NSString stringWithFormat:@"%d", i];
        
        question_array[key] = answerDict;
        
        k += arrayCount;