【发布时间】:2014-11-05 11:19:43
【问题描述】:
在我的 xcode 项目中,我使用 Unirest 库向我的 api 发送带有 json 数据的发布请求:
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"
}
这里发生了什么?
【问题讨论】:
-
显然,您正在发送一个 JSON 字符串作为 JSON“对象”中的键。我不熟悉 UNIRest,但我怀疑它正在进行第二次 JSON 序列化。
标签: ios objective-c json xcode nsjsonserialization