How can i post json string to server

前端 未结 4 1792
清歌不尽
清歌不尽 2020-12-16 08:22

This is json string that I have to post...

{
    \"data\": {
        \"description\": \"\",
        \"current_value\": \"\",
        \"serialno\": \"\",
            


        
4条回答
  •  -上瘾入骨i
    2020-12-16 08:52

    Use following shnchronous request, you can use asynchronous request as well,

    NSError *error;
    
      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:]];
    
      NSData *jsonData = [NSJSONSerialization dataWithJSONObject: options:NSJSONReadingMutableContainers error:&error];
    
    
     [request setHTTPMethod:@"POST"];
     [request setHTTPBody:jsonData];
    
      NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
      //NSLog(@"results string = %@",[[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]);
    
    
     NSDictionary *temp= [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];// This will convert Data to Json format
    

提交回复
热议问题