Smit Saraiya
Smit Saraiya

Reputation: 391

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?

Upvotes: 0

Views: 1074

Answers (1)

robowen5mac
robowen5mac

Reputation: 886

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.

Upvotes: 1

Related Questions