2013-05-31 36 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当您从查询得到你返回的对象。您可能需要将查询更改为用户查询,而不是对象。

我知道这是一个古老的问题,但对于我来说这并不明确,而且我在这个问题上没有完整的线索。希望这有助于。

相关问题