2011-11-05 4 views
0

나는 내 전화 번호의 값을 변경 한 다음 다시 업로드하려면, 내가 그렇게 할 수있는 방법을 알고 싶어요 {"firstname":"A","Contact":{"phone":1234567899,"email":"[email protected]"}}Xcode 4에 json 객체를 게시하는 방법은 무엇입니까?

비동기 NSURL 연결을 사용하여 내 JSON 객체를 얻고있다. 전화 또는 전체 개체에 대해 키 - 값 쌍만 전송해야합니까? { "firstname": "A", "Contact": { "phone": 1234567899, "email": "[email protected]"}} 데이터베이스에서 업데이트하기 위해 전화 번호를 서버에 업데이트했습니다.

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:myUrl]; 
[request setHTTPMethod:@"POST"]; 
[request setValue:@"text/plain" forHTTPHeaderField:@"Content-Type"]; 
[request setHTTPBody:stringInNSData]; 

위의 논리는 거의 모든 곳에서 발견되었지만 구현 방법 및 구현 위치를 알지 못합니다.

답변

2

이것은 실제로 서버와 데이터베이스 저장 방법에 따라 다릅니다. SQL과 같은 데이터베이스를 사용하는 경우 업데이트 할 필드와 함께 업데이트 할 데이터 행을 식별하는 기본 키를 전달해야합니다. 게시물을받는 서버 코드는 전달한 속성을 업데이트하고 나머지 데이터 행은 그대로 둘 수 있습니다.

어디에서 구현할 것인가? 데이터를 변경할 때마다 구현해야합니다. 데이터 변경을 유발하는 UI 요소가있는 경우 해당 요소를 구현할 수 있습니다. 코드 아래에 추가하십시오.

NSURLConnection *urlConnection = [NSURLConnection connectionWithRequest:request delegate:self]; 

그러면 코드가 구현 된 클래스가 연결 위임자로 설정되고 연결이 시작됩니다. 이 방법을 사용하여 업데이트 성공 또는 실패를 처리 할 수 ​​있습니다.

Connection Data and Responses 
– connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite: delegate method Available in iOS 3.0 through iOS 4.3 
– connection:didReceiveData: delegate method Available in iOS 2.0 through iOS 4.3 
– connection:didReceiveResponse: delegate method Available in iOS 2.0 through iOS 4.3 
– connection:willCacheResponse: delegate method Available in iOS 2.0 through iOS 4.3 
– connection:willSendRequest:redirectResponse: delegate method Available in iOS 2.0 through iOS 4.3 
Connection Completion 
– connection:didFailWithError: delegate method Available in iOS 2.0 through iOS 4.3 
– connectionDidFinishLoading: delegate method Available in iOS 2.0 through iOS 4.3 
+0

감사합니다. maudi :-) – codejunkie

+0

문제 없습니다. 프로젝트가 제대로 진행되고있는 것 같습니다. –

+0

네, 그렇습니다 :-) 나는 온라인 제품 등급과 같은 앱을 만들고 있습니다. 이제 나는 다시 그것에 갇혀있다. 사용자가 게시 한 모든 의견에 액세스하고 있습니다. 나는 tableview에 putted하지만 텍스트의 크기가 더 크고 tableview 셀이 1 줄만 표시하는 것과 같은 문제가 있습니다. 나는 tableview의 높이를 조정하는 방법을 찾고있다. – codejunkie

관련 문제