0
軌服務器
我已經通過設置內容類型爲application/JSON和此JSON代碼成功地使用HTTP客戶端做一個帖子:HTTP後W/JSON從iOS的
{
"order": {
"name": "Tia Carter",
"location": "Corams",
"phone_number": "707",
"food": "Bobcat Burger"
}
}
代碼工作完美該訂單已在數據庫中註冊。我正在嘗試將其應用到我的iOS應用程序中,但不斷收到關於json中冒號的語法錯誤。這是客觀C代碼:
NSURL *nsURL = [[NSURL alloc] initWithString:@"http://0.0.0.0:3000/orders.json"];
NSMutableURLRequest *nsMutableURLRequest = [[NSMutableURLRequest alloc] initWithURL:nsURL];
// Set the request's content type to application/x-www-form-urlencoded
[nsMutableURLRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
// Set HTTP method to POST
[nsMutableURLRequest setHTTPMethod:@"POST"];
// Set up the parameters to send.
NSString *paramDataString = [NSString stringWithFormat:@
"{ "order": {"%@:" ="%@","%@:"="%@","%@:"="%@","%@:"="%@"}}", @"name", _name.text, @"location", _location.text, @"phone_number", _phoneNumber.text, @"food", _order.text];
// Encode the parameters to default for NSMutableURLRequest.
NSData *paramData = [paramDataString dataUsingEncoding:NSUTF8StringEncoding];
// Set the NSMutableURLRequest body data.
[nsMutableURLRequest setHTTPBody: paramData];
// Create NSURLConnection and start the request.
NSURLConnection *nsUrlConnection=[[NSURLConnection alloc]initWithRequest:nsMutableURLRequest delegate:self];
我會很感激任何想法或指導。謝謝。