示例:
NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:@"uid",@"_id",@"name",@"loginName",@"pass",@"password" , nil]; //判断Foundation对象能否转化为json对象 if ([NSJSONSerialization isValidJSONObject:dic]) { NSError *error; //NSJSONWritingPrettyPrinted将生成的json数据格式化输出, NSData *data=[NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&error];
NSLog(@"Register JSON:%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);