httpリクエストを介して外部サーバーからログインフォームの読み取りを構築し始めていますユーザー名を取得するためにjsonの結果を解析する必要があります
- (IBAction)getlogin:(UIButton *)sender {
NSString *rawStrusername = [NSString stringWithFormat:@"username=%@",_username.text];
NSString *rawStrpassword = [NSString stringWithFormat:@"password=%@",_password.text];
NSString *post = [NSString stringWithFormat:@"%@&%@", rawStrusername, rawStrpassword];
// NSString *post = @"rawStrusername&rawStrpassword";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
/* NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; */
NSURL *url = [NSURL URLWithString:@"http://www.othaimmarkets.com/my_services_path/user/login.json"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
/* [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; */
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
//NSLog(@"responseData: %@", responseData);
}
私はこの結果を得る:
{"sessid": "g2ev7til6d750ducrkege0cbj2"、 "session_name": "SESS02795057fe9e6b2fc0777bf4057b248f"、 "user":{"uid": "617"、 "name": "mohammed.abdelrasoul@gmail.com"、 "mail": "mo .abdelrasoul @ gmail.com "、" mode ":" 0 "、" sort ":" 0 "、" threshold ":" 0 "、" theme ":" "、" signature ":" "、" signature_format ": "0"、 "created": "1316602317"、 "access": "1352643854"、 "login": "1352666338"、 "status": "1"、 "timezone": "10800"、 "language": "ar "、" pictures ":" "、" init ":" mohammed.abdelrasoul@gmail.com "、" data ":"a:5:{s:18:\ "country_iso_code_2 \"; s:2:\ "SA \"; s:13:\ "timezone_name \"; s:11:\ "Asia / Riyadh \"; s:5 :\ "block \"; a:1:{s:7:\ "webform \"; a:1:{s:15:\ "client-block-88 \"; i:1;}} s:13 :\ "form_build_id \"; s:37:\ "form-3ae73833f08accc7abe5517347ea87eb \"; s:7:\ "contact \"; i:0;} "、" country_iso_code_2 ":" SA "、" timezone_name ":" Asia / Riyadh "、" block ":{" webform ":{" client-block-88 ":1"}、 "form_build_id": "form-3ae73833f08accc7abe5517347ea87eb"、 "contact":0、 "roles":{"2" :"認証されたユーザー"}}}webform \ "; a:1:{s:15:\" client-block-88 \ "; i:1;}} s:13:\" form_build_id \ "; s:37:\" form-3ae73833f08accc7abe5517347ea87eb \ " ; s:7:\ "contact \"; i:0;} "、" country_iso_code_2 ":" SA "、" timezone_name ":" Asia / Riyadh "、" block ":{" webform ":{" client-block -88 ":1"}、 "form_build_id": "form-3ae73833f08accc7abe5517347ea87eb"、 "contact":0、 "roles":{"2":"認証されたユーザー"}}}webform \ "; a:1:{s:15:\" client-block-88 \ "; i:1;}} s:13:\" form_build_id \ "; s:37:\" form-3ae73833f08accc7abe5517347ea87eb \ " ; s:7:\ "contact \"; i:0;} "、" country_iso_code_2 ":" SA "、" timezone_name ":" Asia / Riyadh "、" block ":{" webform ":{" client-block -88 ":1"}、 "form_build_id": "form-3ae73833f08accc7abe5517347ea87eb"、 "contact":0、 "roles":{"2":"認証されたユーザー"}}}client-block-88 ":1"}、 "form_build_id": "form-3ae73833f08accc7abe5517347ea87eb"、 "contact":0、 "roles":{"2":"認証されたユーザー"}}}client-block-88 ":1"}、 "form_build_id": "form-3ae73833f08accc7abe5517347ea87eb"、 "contact":0、 "roles":{"2":"認証されたユーザー"}}}
または、読みやすくするためにフォーマットされています。
{
"sessid":"g2ev7til6d750ducrkege0cbj2",
"session_name":"SESS02795057fe9e6b2fc0777bf4057b248f",
"user":{
"uid":"617",
"name":"mohammed.abdelrasoul@gmail.com",
"mail":"mohammed.abdelrasoul@gmail.com",
"mode":"0",
"sort":"0",
"threshold":"0",
"theme":"",
"signature":"",
"signature_format":"0",
"created":"1316602317",
"access":"1352643854",
"login":"1352666338",
"status":"1",
"timezone":"10800",
"language":"ar",
"picture":"",
"init":"mohammed.abdelrasoul@gmail.com",
"data":"a:5:{s:18:\"country_iso_code_2\";s:2:\"SA\";s:13:\"timezone_name\";s:11:\"Asia/Riyadh\";s:5:\"block\";a:1:{s:7:\"webform\";a:1:{s:15:\"client-block-88\";i:1;}}s:13:\"form_build_id\";s:37:\"form-3ae73833f08accc7abe5517347ea87eb\";s:7:\"contact\";i:0;}",
"country_iso_code_2":"SA",
"timezone_name":"Asia/Riyadh",
"block":{
"webform":{
"client-block-88":1
}
},
"form_build_id":"form-3ae73833f08accc7abe5517347ea87eb",
"contact":0,
"roles":{
"2":"authenticated user"
}
}
}
オブジェクトデータを取得する方法、または結果を解析してユーザー名を取得する方法ヘルプや例をいただければ幸いです