JSON文本不是以数组或对象和选项开头,以允许未设置的片段无法获得响应

时间:2016-03-18 06:23:25

标签: ios objective-c json afnetworking

当我打算使用xe货币转换器api转换货币但没有得到回复时

预期的响应应该像

  

{"术语#34;:" http://www.xe.com/legal/dfs.php""隐私":" http://www.xe.com/privacy.php&#34 ;, "从":" USD""量":1.0,"时间戳":" 2016-03-18T06:22: 00Z""至":[{" quotecurrency":" INR""中间":66.6094587811}]}

我在回复时收到以下错误:

  

错误:错误域= NSCocoaErrorDomain代码= 3840" JSON文本没有以数组或对象开头,并且选项允许未设置片段。" UserInfo = {NSDebugDescription = JSON文本不以数组或对象开头,并且选项允许未设置片段。,NSUnderlyingError = 0x7fa879f70190 {错误域= AFNetworkingErrorDomain代码= -1011"请求失败:未找到(404)&#34 ; UserInfo = -
  {AFNetworkingOperationFailingURLResponseErrorKey = {URL:xecdapi.xe.com/v1/convert_from? } {status code:404,headers {Connection =" keep-alive&#34 ;; " Content-Length的" = 9; "内容类型" =" text / plain;字符集= UTF-8&#34 ;; ,NSLocalizedDescription =请求失败:未找到(404),NSErrorFailingURLKey = xecdapi.xe.com / v1 / convert_from?}}}

我的代码是:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
AFJSONResponseSerializer *jsonResponseSerializer = [AFJSONResponseSerializer serializer];
NSMutableSet *jsonAcceptableContentTypes = [NSMutableSet setWithSet:jsonResponseSerializer.acceptableContentTypes];
[jsonAcceptableContentTypes addObject:@"text/plain"];
jsonResponseSerializer.acceptableContentTypes = jsonAcceptableContentTypes;
manager.responseSerializer = jsonResponseSerializer;
[manager.requestSerializer setValue:@“xxxxxxxxninternationalfze988134762" forHTTPHeaderField:@"User Name"];
[manager.requestSerializer setValue:@“xxxxqngksq5nuqmmf7tjgcihak" forHTTPHeaderField:@"Password"];
NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
[params setObject:@"USD" forKey:@"from"];
[params setObject:@"INR" forKey:@"to"]; 

0 个答案:

没有答案