如何将RKObjectMapping(Reskit)转换为json字符串?

时间:2013-01-07 19:57:27

标签: iphone ios

我有以下代码:

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]; 

这段代码运行正常...但是我有一个问题,我需要向Rest API发送一个JSON对象(比如String),我有一个RKObjectMapping,其值应该发送给Rest Api。

可以将RKObjectMapping转换为JSON吗?

1 个答案:

答案 0 :(得分:1)

除非您自己编写JSON库,否则不能本机执行此操作。否则,考虑利用类似JSONKit的东西,它易于使用且运行良好。

Here's an example usage