CFPropertyList用法

时间:2010-08-08 17:11:32

标签: php iphone

我正在尝试使用CFPropertyLIst将帐户已从我的服务器过期的用户列表返回到我的iphone目标c应用程序,但NSURLConnection回调中返回的数据始终为null。我认为我对CFPropertyList的使用可能不正确,但无法解决为什么不

$query="SELECT user, UNIX_TIMESTAMP(created) AS created_ts FROM  accounts"
$result = mysql_query($query)  


$userarray = new CFArray ();
while($row = mysql_fetch_array($result))
{
    $user = $row['user'];
    $created_ts = $row['created_ts'];

   $entry = new CFDictionary();
   $entry->add('user', new CString($user));
   $entry->add('created_ts', new CFNumber($created_ts));
   $userarray->add($entry);

}

$plist = new CFPropertyList();
$plist->add($userarray);
$plist->toXML();
var_dump($plist);

目标C

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    // We have got everything so no longer need the connection so release it.
    [theConnection release];
    theConnection = nil;

NSString *errorString = nil;
NSArray *array = [[NSPropertyListSerialization 
                       propertyListFromData:theData
                       mutabilityOption:NSPropertyListImmutable
                       format:nil
                       errorDescription:&errorString] retain];

}

在这里,我总是在第1行遇到意外的角色 因为plist的格式看起来很好,但仍然总是出现此错误

对象(CFPropertyList)#5(17)
   {       [ “文件:保护”] => NULL
      [ “格式:保护”] => INT(0)
      [ “值:保护”] =>数组(1){
      [0] =>对象(CFArray)#1(2)       {        [ “iteratorPosition:保护”] =>        INT(0)        [ “值:保护”] =>        数组(1){
       [0] =>对象(CFDictionary)#2(3)         {
          [ “iteratorPosition:保护”] => INT(0)
          [ “iteratorKeys:保护”] => NULL
          [ “值:保护”] =>阵列(2)           {
            [ “用户”] =>对象(CFString)#3(1){
              [ “值:保护”] =>
              string(9)“anonymous”
            }
            [ “created_ts”] =>
            对象(CFNumber)#4(1){
              [ “值:保护”] =>
              INT(1281263044)
            }
           }
         }
        }
      }
     }
  [ “iteratorPosition:保护”] => INT(0)
  [ “iteratorKeys:保护”] => NULL
  [ “内容:保护”] => NULL
  [ “POS:保护”] => INT(0)
  [ “uniqueTable:保护”] =>
  数组(0){
  }
  [ “countObjects:保护”] => INT(0)
  [ “stringsize的:保护”] => INT(0)
  [ “intSize:保护”] => INT(0)
  [ “miscSize:保护”] => INT(0)
  [ “objectRefs:保护”] => INT(0)   [ “writtenObjectCount:保护”] => INT(0)   [ “objectTable:保护”] =>   array(0){   }
  [ “objectRefSize:保护”] => INT(0)
  [ “偏移:保护”] =>
  数组(0){
  }
}

1 个答案:

答案 0 :(得分:1)

你的输出没有一个plist;它是CFPropertyList的内部表示。请查看http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man5/plist.5.html获取一个简短的样本plist。

你的问题是$ plist-> toXML()不会修改$ plist;它返回$ plist对象的XML表示形式的字符串。变化:

$plist->toXML();
var_dump($plist);

$xml = $plist->toXML();
var_dump($xml);