简体   繁体   English

如何使用json将更新的数据发送到iPhone中的服务器?

[英]How to send the updated data using json to server in iphone?

am using web services (JSON). 正在使用Web服务(JSON)。 from json am getting data this data loading into tableview am trying to edit this data but after edit the data how to send this updated data to server. 从json获取数据,此数据正在加载到tableview中,试图编辑此数据,但是在编辑数据后如何将更新后的数据发送到服务器。 please any one help me? 请有人帮我吗?

try this will help you.. this is the post method for updating data in WS . 尝试这样做将对您有帮助。.这是在WS中更新数据的发布方法。

NSString *post =[NSString stringWithFormat:@"uid=%@&firstname=%@&lastname=%@&phone=%@&bday=%@&about_me=%@&image=%@&image_code=%@&contact_number=%@",LoginID,fname,lname,cn,bday,abtme,strimage11,c11,cn];


NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];


NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"YOUR LINK"]];

[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

NSError *error;
NSURLResponse *response;
NSData *uData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:uData encoding:NSUTF8StringEncoding];
//    
NSMutableDictionary *temp = [data JSONValue];
//    
NSLog(@"%@",temp);

I am assuming you have your edited data, then 我假设您已经编辑了数据,那么

  1. Form your json. 形成您的json。 There are several libraries out there which can help you. 有几个库可以为您提供帮助。
  2. Know the hostname of your server. 知道服务器的主机名。
  3. Know which API to hit on your server. 知道要在您的服务器上使用哪个API。
  4. then pass this json as POST (GET is also ok, but POST is preferred). 然后将此JSON作为POST传递(GET也可以,但首选POST)。
  5. Process this received json on your server. 在服务器上处理此收到的json。

Hope this helps. 希望这可以帮助。 Nothing much to it actually. 其实没什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM