简体   繁体   中英

How to call WebService json objectiveC iOS for calling function

NSString *urlString = [NSString 

    stringWithFormat:@"http://192.168.1.15/abc/service.asmx?op=GetCenter"];

        NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

        NSData *data = [[NSData alloc] initWithContentsOfURL:url];

        NSError *error;

        NSMutableArray *json =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];



        NSLog(@"%@",[json description]);

I have try this but it returns null value insted of call function.

Program ended with exit code: 9(lldb) 

How to recognized if webserive is called or not or how call that function?

If you could provide a bit more information as to what you mean by the function is not called, that would be very helpful, is there any stack trace or other information shown when it crashes?

I would troubleshoot this by stepping through each line of code in the debugger to make sure you are getting data back and then as suggested to print out the error from the serialization function.

It also might be worth using these methods:

NSString* newStr = [NSString stringWithContentsOfURL:url encoding: NSUTF8StringEncoding error:&error];

or

NSString* newStr = [[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding];

to get a string from your URL or data once you have downloaded it and then print out or view the contents.

Longer term you might want to think about using something like AFNetworking to do your networking calls as what you have is synchronous and ideally, you should be doing all networking asynchronously.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM