2013-05-31 39 views
1

嗨,我想知道如何從ParseObject獲取ParseUser對象。我需要這樣做,因爲ParseQuery返回一個List。這是我的代碼,謝謝你的幫助!如何將ParseObject轉換爲ParseUser

 // get the currentUser 
     currentUser = ParseUser.getCurrentUser(); 
     List<ParseObject> friendsList = currentUser.getList("friendsList"); 

     // search for the person the user wants to add as a friend 
     List<ParseObject> userResults = new ArrayList<ParseObject>(); 
     ParseQuery otherUserQuery = ParseUser.getQuery(); 
     otherUserQuery.whereEqualTo("username", "jyo2"); 
     try { 
      userResults = otherUserQuery.find(); 
     } catch (ParseException e1) { 
      // fail 
      e1.printStackTrace(); 
     } 

     // get the friend from the query if there was one and add it to the 
     // currentUser friends list 
     if (userResults.size() != 0) { 
      ParseObject currentObject = userResults.get(0); 
      friendsList.add(currentObject); 
      currentUser.put("friendsList", friendsList); 
     } 
     // save the update 
     try { 
      currentUser.save(); 
     } catch (ParseException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     // try to view the friends 
     List<ParseObject> currentFL = currentUser.getList("friendsList"); 
     ParseObject currentPU = currentFL.get(0); 
     System.out.println("THIS IS SIZE" + currentFL.size()); 
     System.out.println(currentPU.get("name")); 

回答

0

我不認爲你需要以「鑄造」是ParseUser,一個parseuser是的parseObject爲好,除了有連接到它的一些基本的預先定義的屬性,您可以查詢反正喜歡你「d查詢沒有任何其他的parseObject

3

使用在解析現有的‘用戶’類,但使用

@ParseClassName("_User") 
public class PUser extends ParseUser { 

按本article繼承它。子類化此對象時,實際上您特別需要參考_User「ParseClassName」。這是超級毛茸茸的,因爲對於其他類你只需要用Parse使用它的字面名稱來註冊這個類,因爲對於其他的類你可以使用Parse數據瀏覽器,在這個例子中是「User」,「Info」, 「郵報」等,但用戶類明確要求下劃線

編輯對不起,我應該提到,那麼你乾脆投子類PUser當您從查詢得到你返回的對象。您可能需要將查詢更改爲用戶查詢,而不是對象。

我知道這是一個古老的問題,但對於我來說這並不明確,而且我在這個問題上沒有完整的線索。希望這有助於。

相關問題