2014-11-05 104 views
-1

在我的Xcode项目不正确的JSON对象我送使用JSON数据POST请求使用Unirest库我的API:NSJSONSerialization问题。发送到API

NSDictionary *jsonObj = @{@"access_token": accessToken}; 

    UNIHTTPJsonResponse* response = [[UNIRest postEntity:^(UNIBodyRequest* request) { 
    [request setUrl:@"http://localhost:9000/auth/facebook/token"]; 
    [request setHeaders:headers]; 
    // Converting NSDictionary to JSON: 
    [request setBody:[NSJSONSerialization dataWithJSONObject:jsonObj options:0 error:nil]]; 
    }] asJson]; 

检查时jsonObj格式正确无误。

但在服务器端,我看到了这个对象:

{ 
    '{"access_token":"12345678910"}': '' 
    } 

当它应该是:

{ 
     "access_token":"12345678910" 
    } 

这到底是怎么回事?

+0

显然,您正在发送JSON字符串作为JSON“对象”中的键。我对UNIRest不熟悉,但我怀疑它正在做第二个JSON序列化。 – 2014-11-05 12:36:41

回答

1

我怀疑这与asJson方法UNIHTTPJsonResponse有关。

我的猜测是,它采取了身体等内容...然后“转换”为JSON。

所以,当这已经是JSON的时候,它又一次结束了。

+0

我试过了没有图书馆的帖子请求,发生了同样的情况。 – jeh 2014-11-05 12:35:44