ios-iPhone应用-JSON请求失败

问题描述

iPhone应用-JSON请求失败
Json格式如下,要发送请求到服务器,但是返回的是错误500。

{""firstName"":""Sharath K""lastName"":""babu""moMerchantAddresses"":[{""email"":""abc@abc.co.in""}]} >

谢谢您的帮助。

 NSMutableArray *objects =  [NSMutableArray  arrayWithObjects:@""Sharath""@""babu""@""[{""email"":""abc@abc.co.in""}]"" nil];        NSMutableArray *keys = [NSMutableArray arrayWithObjects:@""firstName""@""lastName""@""moMerchantAddresses"" nil];NSMutableDictionary  *jsonDict = [NSMutableDictionary dictionaryWithObjects:objects forKeys:keys];NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict                                                   options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string                                                     error:nil];NSString *postLength = [NSString stringWithFormat:@""%d""[jsonData length]];ServiceInterface *service = [[ServiceInterface alloc] init];service.theDelegate = self;service.theSuccessMethod = @selector(responseMerchantCreationService:);service.theFailureMethod = @selector(requestFailedWithError:);[self addServiceInterfaceToServiceStack:service];NSString* stringURL  =  [kBase_URL stringByAppendingString:@""/merchant/create""];NSString* webStringURL  =  [stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];NSURL* url  =  [NSURL URLWithString:webStringURL];NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];[request setHTTPMethod:@""POST""];[request setValue:postLength forHTTPHeaderField:@""Content-Length""];[request setValue:@""application/json"" forHTTPHeaderField:@""Accept""];[request setValue:@""application/json"" forHTTPHeaderField:@""Content-Type""];[request setHTTPBody:jsonData];[request setTimeoutInterval:30.0f];NSLog(@""request file :: %@""request);[service startWithRequest:request];service = nil;

解决方案

NSMutableDictionary *emailDict = [[NSMutableDictionary alloc] initWithCapacity:0];[emailDict setObject:@""abc@abc.co.in"" forKey:@""email""];NSMutableArray *emailArr = [ [NSMutableArray alloc] init];[emailArr addObject:emailDict];NSMutableDictionary *mainDict = [[NSMutableDictionary alloc] initWithCapacity:0];[mainDict setObject:@""Sharath"" forKey:@""firstName""];[mainDict setObject:@""babu"" forKey:@""lastName""];[mainDict setObject:emailDict forKey:@""moMerchantAddresses""];

修改mainDict为:

NSData *jsonData = [ NSJSONSerialization dataWithJSONObject:mainDict options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string                                                         error:nil];
时间: 2024-08-26 09:17:07

ios-iPhone应用-JSON请求失败的相关文章

ajax 请求参数为空请求是json,有参数就变成HTML 导致请求失败

问题描述 ajax 请求参数为空请求是json,有参数就变成HTML 导致请求失败 如题: $.ajax({ type : "post", url : url, dataType : 'json', data : param, error : function(data) { alert("AJAX查询数据失败."); }, success : function(data) { var entity = data.data; // 获取模板 var source =

IIS7.5 POST请求JSON文件失败

问题描述 在IIS7.5通过POST请求JSON文件失败,但是如果使用GET方式,请求成功.以下是Web.config中的配置.<system.webServer><staticContent><mimeMapfileExtension=".json"mimeType="text/json"/></staticContent><handlers><addname="json"pat

iOS - NetRequest 网络数据请求

1.网络请求 1.1 网络通讯三要素 1.IP 地址(主机名): 网络中设备的唯一标示.不易记忆,可以用主机名(域名). 1) IP V4: 0~255.0~255.0~255.0~255 ,共有 2^8^4 = 2^32 = 42 亿. 2) 本地回环地址: 每台机器都有自己的本地回环地址,ip 为 127.0.0.1 ,主机名为 localhost.如果 127.0.0.1 ping 不通,则网卡不正常. 本地 hosts 文件修改,终端: $ cd /etc $ sudo vim host

struts 2-问题:利用struts自带的json机制,期望从后台获取json数据失败,求帮助

问题描述 问题:利用struts自带的json机制,期望从后台获取json数据失败,求帮助 问题:利用struts自带的json机制,期望从后台获取json数据失败,求帮助 ############################################################## struts 2.3.20 struts.xml <package name="json" extends="json-default" namespace=&qu

eclipse-android post json 数据失败 急求啊!!!!!

问题描述 android post json 数据失败 急求啊!!!!! 5C 用eclipse java写了一个post方法可以post成功,但是用android 用同样的方法上传失败,搞了两三天了,急求啊!!!!!!post 方法public static void appadd(String weburlString json) { try { //鍒涘缓杩炴帴 URL url = new URL(weburl); HttpURLConnection connection = (HttpU

ios-使用AFNetWorking 上传字符串,请求失败,Request failed: 请求太大

问题描述 使用AFNetWorking 上传字符串,请求失败,Request failed: 请求太大 我要把图片换成nsdata,然后再用base64encoding,把encoding后生成的字符串上传到 服务器,就出这个问题, 报错信息:err:Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: 请求太大 (413)" 我同事用的ASIHTTPRequest库就没问

微信在线接口调试请求失败是什么意思

问题描述 解决方案 解决方案二:没遇见过,可能是他们内部错误吧.微信开发,我刚完成.调用文本消息接口的代码,发给楼主一下.publicstringGroupsSendAll(stringACCESS_TOKEN,stringresult){stringwxurl="https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token="+ACCESS_TOKEN;stringdata="{"touser&q

TP-Link ID发送请求失败怎么回事

TP-Link ID发送请求失败怎么回事   TP-Link ID发送请求失败原因: 出现该问题的根本原因为:路由器与TP-LINK云服务器之间无法建立连接,可能原因包括路由器当前未连网.云服务器暂时性的异常.某些特定宽带线路问题等等. 用户与TP-Link云服务器通信示意图 可以通过排查法解决: 首先确认连接TP-Link路由器的手机或电脑能否正常上网,然后参照以下方法加以解决; 情形一:手机电脑能正常上网. 如果手机电脑都能正常通过连接路由器上网,而出现TP-Link ID发送请求失败,则可

SQL Server 请求失败问题的解决方案

  SQL2005无法启动SQL Server 请求失败或服务未及时响应 停用"VIA协议"问题解决."VIA协议"停用方法:开始->程序->Microsoft SQL Server 2005->配置工具->SQL Server Configuration Manager ->打开后找到"SQL Server 2005 网络配置"->MSSQLSERVER 属性的协议 在右边的属性框中把"VIA协议&