Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在json解析中向Http请求POST方法发送json数据_Objective C_Json_Ios7_Http Post - Fatal编程技术网

Objective c 如何在json解析中向Http请求POST方法发送json数据

Objective c 如何在json解析中向Http请求POST方法发送json数据,objective-c,json,ios7,http-post,Objective C,Json,Ios7,Http Post,我需要解析下面的字符串以在iOS中发布方法 "jsonData":{"empId":"cxvd","password":"sfsd"} 但我得到的错误是 Res:Tomcat错误 HTTP状态400-所需的字符串参数“jsonData”不存在 //------ Method I have used to Parse is ---------- // +(void) requestToServerForLogin:(NSString*)userName andPassward: (NSStri

我需要解析下面的字符串以在iOS中发布方法

"jsonData":{"empId":"cxvd","password":"sfsd"}
但我得到的错误是

Res:Tomcat错误

HTTP状态400-所需的字符串参数“jsonData”不存在

//------ Method I have used to Parse is ---------- //

+(void) requestToServerForLogin:(NSString*)userName andPassward: (NSString*)password  onCompletion:(RequestCompletionHandler) handler
{
    NSString *url = [Ip stringByAppendingString:@"login"];

    NSString *jsonString = [NSString stringWithFormat:@"\"jsonData\":{\"empId\":\"%@\",\"password\":\"%@\"}",
                                                      userName,
                                                      password ];

     NSURL *nsurl = [NSURL URLWithString:url];

     NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:nsurl];
     [urlRequest setTimeoutInterval:60.0f];
     [urlRequest setHTTPMethod:@"POST"];
     [urlRequest setValue:@"application/json"
     forHTTPHeaderField:@"Content-type"];

     NSString *body = jsonString1;

     [urlRequest setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
     NSLog(@"urlRequest :%@",[body dataUsingEncoding:NSUTF8StringEncoding]);

     NSOperationQueue *queue = [[NSOperationQueue alloc] init];

     [NSURLConnection sendAsynchronousRequest:urlRequest
                                       queue:queue
                           completionHandler:^(NSURLResponse *response,
                                               NSData *data1, NSError *error) 
                                             {
                                                  NSString *res = [[NSString alloc] initWithData:data1 encoding:NSUTF8StringEncoding];
                                                  if(handler) handler(res,error);
                                             }];

}

提前感谢

有很多代码。
substringToIndex
substringfromfromindex
错误,不应在代码中

使用字典的文字语法:

NSDictionary *jsonDict = @{@"jsonData":@{@"password":password, @"empId":userName}};
NSData* jsonData =  [NSJSONSerialization dataWithJSONObject:jsonDict options:0 error:&error];

但是substringFromIndex我用来从Json字符串中删除花括号,因为我在下面遇到了错误--HTTP状态400-必需的字符串参数'jsonData'不存在。我以前使用过这种格式,它给我的输入是--input=={“jsonData”:{“empId”:“wfr”,“密码”:“wtrt”}但是我需要输入字符串as==“jsonData”:{“empId”:“wfr”,“password”:“wtrt”}如果有其他解决方案,请告诉我..我甚至使用了多部分,但没有任何用处.任何人能帮我解析这个字符串“jsonData”:{“empId”:“1111”,“password”:“######”}解析完所有我得到的东西后,“jsonData”不存在