I am a beginner in xcode please help me How to get the user name & Password from the web service and how to validate it when the sign in button is pressed? Thanks in advance..
3 Answers
Refer these Links and you'll be fine.
iPhone/iOS JSON parsing tutorial
As far as validating your username and password is concerned, first of all, you'll have to parse and store your data in NSArray or NSDictionary and then extract the needed data from it. Then you can check if the received data is correct or not by comparing it with the expected data. Try doing something like this. This is not the exact solution and you'll have to work around your way.
NSString *link = [NSString stringWithFormat:@"yourServiceURL"];
NSString *encdLink = [link stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:encdLink];
NSData *response = [NSData dataWithContentsOfURL:url];
NSError *error;
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:response options: NSJSONReadingMutableContainers error: &error];
Now you have your data in the array and extract it out using objectForKey
or valueForKey
.
You can't access "json web services". You can recieve awnseres from a web service in json format. Do you even know how to acces the web services? Do you have coded it? Please describe better!
To try to awnser your question anyway, if, for example your service is written in WCF. And your method is called "getUserNamePassword" you would call it with a http request incl your methodname. For example: localhost/Myservice.svc/getUserNamePassword. That would return Json if you setup the config file from wcf right.
Greets

- 1,337
- 3
- 16
- 33
-
Thank you and am not coded yet could you please explain me how to get the datas in some simple Coding... – Ragul Jun 13 '14 at 07:24
-
WCF: http://www.codeproject.com/Articles/167159/How-to-create-a-JSON-WCF-RESTful-Service-in-sec XCODE: http://stackoverflow.com/questions/982622/consume-wcf-web-service-using-objective-c-on-iphone/988884#988884 – nixn Jun 13 '14 at 07:28
You can use this code and fetch data from array by using valueForKey method
NSArray *arr1=[NSJSONSerialization JSONObjectWithData:responseData
options:NSJSONReadingAllowFragments error:&error];
NSArray *epi=([arr1 valueForKey:@"Response"]);
NSString *genderString=[[epi objectAtIndex:0] valueForKey:@"username"] ;
Happy Coding :) Hope this will help you..

- 239
- 1
- 10