当我使用JSONValue响应来自SOAP WebService的字符串时,NSDictionary为空

时间:2012-10-09 13:18:46

标签: asp.net json web-services xcode4.2 asihttprequest

Currentyl我正在使用XCode4.2.1开发IOS应用程序。我的应用程序是从asp.net Web服务获取json值。这是我获取Web服务的代码。

-(BOOL)GrabbingStudentsWebService{
NSURL *url=[NSURL URLWithString:@"http://www.cheaptal.com/easypft/Service1.asmx"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setRequestMethod:@"POST"];
[request addRequestHeader:@"Content-Type" value:@"text/xml; charset=utf-8"];
[request addRequestHeader:@"SOAPAction" value:@"http://cheaptal.com/GetAllStudents"];

NSString *soapMsg= [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                    "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                    "<soap:Body>"
                    "<GetAllStudents xmlns=\"http://cheaptal.com/\" />"
                    "</soap:Body>"
                    "</soap:Envelope>"];


NSString *messageLength = [NSString stringWithFormat:@"%d",[soapMsg length]];
[request addRequestHeader:@"Content-Length" value:messageLength];
[request appendPostData:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
[request setDelegate:self]; 
[request startAsynchronous]; 

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = @"Sync...";

return TRUE;}

这是我的请求已完成代码

- (void)requestFinished:(ASIHTTPRequest *)request{    
[MBProgressHUD hideHUDForView:self.view animated:YES];
if (request.responseStatusCode == 200) {

    NSString *response = [request responseString];
    txtview.text = response;
    NSDictionary *insidejson=[[NSDictionary alloc] init];
    insidejson = [response JSONValue]; //my problem is here.
} else {
    txtview.text = @"cannot retrieve data.";
}}

这是来自网络服务的响应代码:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetAllStudentsResponse xmlns="http://cheaptal.com/"><GetAllStudentsResult>[{"stu_name":"COEMAW","stu_sitreach":10.5,"stu_broadjump":12.3,"stu_napfarun":"11:54.32"},{"stu_name":"LINA","stu_sitreach":2.5,"stu_broadjump":5.3,"stu_napfarun":"10:54.22"},{"stu_name":"ULD27","stu_sitreach":6.5,"stu_broadjump":7.3,"stu_napfarun":"09:54.12"},{"stu_name":"MOTTA","stu_sitreach":7.5,"stu_broadjump":9.3,"stu_napfarun":"10:33.52"}]</GetAllStudentsResult></GetAllStudentsResponse></soap:Body></soap:Envelope>

我的问题是当我尝试使用 JSONValue insidejson = [response JSONValue])将响应字符串解析为 NSDictionary 时; ),insidejson变量里面没有值。我仍然不知道为什么 insidejson 是空的。

非常感谢您的帮助! dartfrog

0 个答案:

没有答案