creating JSON format in Objective C

后端 未结 6 449
感动是毒
感动是毒 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 08:11

        check this code-
      NSMutableDictionary *students=[NSJSONSerialization JSONObjectWithData:webData        options:0 error:nil];
          for (NSDictionary *dictionofstudents in students)
          {
               NSMutableDictionary *results=[dictionofstudents objectForKey:@"results"];
               for (NSDictionary *dictionofresults in results)
               {
                   NSMutableDictionary *grade1=[dictionofresults objectForKey:@"Grade1"];
                   for (NSDictionary *dictionofgrade1 in grade1) 
                   {
                       NSString *studentresult=[dictionofgrade1 objectForKey:@"studentresult"];
                       NSString *marksheet=[dictionofgrade1 objectForKey:@"marksheet"];
                       [arrayofstudentresult addObject:studentresult];
                       [arrayofmarksheet addObject:marksheet];
                   }
                   NSString *ID=[dictionofresults objectForKey:@"ID"];
                   NSString *name=[dictionofresults objectForKey:@"Name"];
                  [arrayofID addObject:ID];
                  [arrayofname addObject:name];
               }
          }
    

提交回复
热议问题