creating JSON format in Objective C

后端 未结 6 435
感动是毒
感动是毒 2020-12-10 07:19

For an application i want to create a JSON in format as mentioned below,

\"Students\" : {
    \"results\": {
        \"Grade1\": {
            \"studentresul         


        
6条回答
  •  囚心锁ツ
    2020-12-10 07:57

    Required Data , You can get this way . Just convert that stud dict in JSon or any other format you want. Remove that array , You don't need it , As you mentioned it in the required format.

    NSMutableDictionary *gradedetails = [[NSMutableDictionary alloc] init];
    [gradedetails setObject:@"pass" forKey:@"studentresult"];
    [gradedetails setObject:@"provided" forKey:@"marksheet"];
    
    NSMutableDictionary *sdetails = [[NSMutableDictionary alloc] init];
    [sdetails setObject:@"01" forKey:@"ID"];
    [sdetails setObject:@"Name" forKey:@"Student1"];
    [sdetails setObject:gradedetails forKey:@"Grade1"];
    
    NSMutableDictionary *results = [[NSMutableDictionary alloc] init];
    [results setObject:sdetails forKey:@"results"];
    
    NSMutableDictionary *stud = [[NSMutableDictionary alloc] init];
    [stud setObject:results forKey:@"Students"];
    
    NSLog(@"Required Format Data is %@",stud);
    

提交回复
热议问题