2013-01-07 1 views
0

나는 다음과 같은 코드를 가지고 :RKObjectMapping (Reskit)을 json 문자열로 변환하는 방법은 무엇입니까?

NSString *url =  @"http://mysite.com" 
RKURL *baseURL = [RKURL URLWithBaseURLString:url]; 
objectManager = [RKObjectManager objectManagerWithBaseURL:baseURL]; 
objectManager.client.baseURL = baseURL; 
objectManager.serializationMIMEType = RKMIMETypeJSON; 

NSString *token = @"Token is getting from rest API" 
[[objectManager client] setValue:token forHTTPHeaderField:@"token"]; 

RKClient *client= [objectManager client];  
RKRequest * therequest = [client requestWithResourcePath:@"/create"]; 


[therequest setHTTPBodyString:@"{user:user}"]; //Here receive a JSON value 
[therequest setMethod:RKRequestMethodPOST]; 
[therequest setDelegate:self];        
[therequest send]; 

이 코드는 잘 작동 ...하지만 난 나머지의 API (문자열 등) JSON 개체에 보낼 필요가, 문제가 나는 값과 RKObjectMapping이 나머지 Api로 보내야합니다.

RKObjectMapping을 JSON으로 변환 할 수 있습니까?

답변

1

직접 JSON 라이브러리를 작성하지 않으면 기본적으로 수행 할 수 없습니다. 그렇지 않은 경우 JSONKit과 같은 것을 활용하면 사용하기 쉽고 잘 작동합니다.

Here's an example usage.

+0

예, 생각했는데 ... 가능하면 알 수 싶습니다 ... JSON 또는 NSDictionary로 RKObjectMapping ..하지만 답장을 주셔서 감사합니다 +1 : –

+0

내 잘못, 내가 읽고있었습니다. 귀하의 질문에 조금. – Madbreaks

+0

이 질문은 귀하의 문제를 해결하는 것으로 보이지만 그 반대입니다. 아마도 도움이 될 수 있습니다. http://stackoverflow.com/questions/12057141/nested-objects-in-nsdictionary-with-restkit – Madbreaks

관련 문제