how to create json in objective-c

后端 未结 6 1458
眼角桃花
眼角桃花 2020-12-31 04:19
NSData* jsonDataToSendTheServer;

NSDictionary *setUser = [NSDictionary
            dictionaryWithObjectsAndKeys:[@\"u\" stringByAppendingString:my.id],@\"id\",
             


        
6条回答
  •  情歌与酒
    2020-12-31 04:51

    You can try following to create JSON:

    NSArray *objects=[[NSArray alloc]initWithObjects:objects here,nil];
    NSArray *keys=[[NSArray alloc]initWithObjects:corresponding keys of objects,nil];
    NSDictionary *dict=[NSDictionary dictionaryWithObjects:objects forKeys:keys];
    NSData *jsonData=[NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    

    this worked perfectly in my case

提交回复
热议问题