pickerview에서 사용할 배열을 채우려합니다. 배열의 데이터는 데이터베이스 테이블에서 생성됩니다.json_encoded 데이터를 UIPickerView - Xcode에 사용할 배열로 구문 분석합니다.
I는 (PHP에서 생성) 다음 JSON_ENCODED 어레이 가지고 WEBSERVICE의 PHP 코드
{"result":
[
{"id":"3","quivername":"Kite Boarding"},
{"id":"4","quivername":"Live and Die in LA"},
{"id":"14","quivername":"Bahamas Planning"},
{"id":"15","quivername":"My Trip to India"},
{"id":"16","quivername":"Snowboarding"}
]
}
UPDATE를
I는 웹 서비스로서 이러한 기능 실행 I는 이것을 사용
passport($_SESSION['IdUser'])
function passport($userid) {
$result = query("SELECT id, quivername FROM quivers WHERE userid = $userid");
if (!$result['error']) {
print json_encode($result);
} else {
errorJson('Can not get passports');
}
}
function query() {
global $link;
$debug = false;
//get the sql query
$args = func_get_args();
$sql = array_shift($args);
//secure the input
for ($i=0;$i<count($args);$i++) {
$args[$i] = urldecode($args[$i]);
$args[$i] = mysqli_real_escape_string($link, $args[$i]);
}
//build the final query
$sql = vsprintf($sql, $args);
if ($debug) print $sql;
//execute and fetch the results
$result = mysqli_query($link, $sql);
if (mysqli_errno($link)==0 && $result) {
$rows = array();
if ($result!==true)
while ($d = mysqli_fetch_assoc($result)) {
array_push($rows,$d);
}
//return json
return array('result'=>$rows);
} else {
//error
return array('error'=>'Database error');
}
}
을 NSNetworking을 사용하여 웹 사이트/웹 사이트에 연결하는 Xcode의 코드 ...
-(void)getPassports {
//just call the "passport" command from the web API
[[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:
@"passport",@"command",
nil]
onCompletion:^(NSDictionary *json)
{
//got passports, now need to populate pickerArray1
if (![json objectForKey:@"error"])
{
//success, parse json data into array for UIPickerview
}
else
//error, no passports
{
// error alert
}
}];
}
다음이 필요합니다.
1) NSMutable 배열에 quivername 값을 어떻게 채울 수 있습니까? 내가 먼저 배열의 행 수를 "계산"나를 필요로하는 for 루프를 실행할 필요가 있으리라 믿고있어
pickerArray1 = [[NSMutableArray alloc] initWithObjects:@"Kite Boarding",
@"Live and Die in LA", @"Bahamas Planning", @"My Trip to India", @"Snowboarding",
nil];
,하지만 난 :이처럼 보이는 결과를 얻으려고 확실하지 않아. json_array의 행 수를 계산하거나 NSMutable 배열을 만드는 방법을 모르겠습니다. 사전에
감사합니다 ...
어떻게 iOS 앱에 JSON을 PHP를 생성지고있다? 더 많은 코드를 제공 할 수 있습니까? – propstm