2012-05-01 11 views
1

私の問題はこれです:私はSoapObjectを持っています。オブジェクトの配列へのkSoap応答の解析

 if(sResult != null) 
     { 
      SoapObject soapresults = (SoapObject)sResult.getProperty(0); 

      int count = soapresults.getPropertyCount(); 

      ChildStatus[] children = new ChildStatus[count]; 

      for (int i = 0; i < count; i++) 
      { 
       SoapObject kid = (SoapObject)soapresults.getProperty(i); 
       ChildStatus childStatus = new ChildStatus(); 
       SoapObject value = (SoapObject)kid.getProperty("Value"); 
       SoapObject info = (SoapObject)value.getProperty("Info"); 

       childStatus.CheckOutPlanned = value.getPropertyAsString("CheckOutPlannedTime"); 
       childStatus.CurrentStatus = value.getPropertyAsString("CurrentStatus"); 
       childStatus.FullName = info.getPropertyAsString("FullName"); 
       childStatus.ID = info.getPropertyAsString("Id"); 
       childStatus.KindergardenID = info.getPropertyAsString("KindergardenId"); 
       childStatus.URL = info.getPropertyAsString("ThumbnailUrl"); 

       String pickUpBy = value.getPropertyAsString("PickUpBy"); 


       if(pickUpBy.equalsIgnoreCase("anyType{}")) 
       { 
        System.out.println("Ja"); 
        pickUpBy = "none"; 
       } else if(pickUpBy.equalsIgnoreCase("En anden forælder")) 
       { 
        childStatus.PickUpWithKidID = value.getPropertyAsString("PickUpWithKidId"); 
        childStatus.PickUpWithKidName = value.getPropertyAsString("PickUpWithKidName"); 
       } 

       childStatus.PickUpBy = value.getPropertyAsString("PickUpBy"); 

       children[i] = childStatus; 
      } 

      System.out.println("Size: " + children.length); 

と私のオブジェクトがこれです:

私は正常に私のコードはこれです...(?私は思う)

を別のネストされた要素を見つけるために、それを介して反復し、オブジェクトにそれらを保存しました

public class ChildStatus implements KvmSerializable 
{ 
    public String CheckOutPlanned; 
    public String CurrentStatus; 
    public String FullName; 
    public String ID; 
    public String KindergardenID; 
    public String URL; 
    public String PickUpBy; 
    public String PickUpWithKidID; 
    public String PickUpWithKidName; 

    public ChildStatus(){} 

    public ChildStatus(String checkOutPlanned, String currentStatus, String fullName, String id, String kindergardenID, String url, String pickUpBy, String pickUpWithKidID, String pickUpWithKidName) 
    { 
     CheckOutPlanned = checkOutPlanned; 
     CurrentStatus = currentStatus; 
     FullName = fullName; 
     ID = id; 
     KindergardenID = kindergardenID; 
     URL = url; 
     PickUpBy = pickUpBy; 
     PickUpWithKidID = pickUpWithKidID; 
     PickUpWithKidName = pickUpWithKidName; 
    } 

    public Object getProperty(int arg0) { 
     // TODO Auto-generated method stub 
     switch(arg0) 
     { 
     case 0: 
      return CheckOutPlanned; 
     case 1: 
      return CurrentStatus; 
     case 2: 
      return FullName; 
     case 3: 
      return ID; 
     case 4: 
      return KindergardenID; 
     case 5: 
      return URL; 
     case 6: 
      return PickUpBy; 
     case 7: 
      return PickUpWithKidID; 
     case 8: 
      return PickUpWithKidName; 
     } 

     return null; 
    } 

    public int getPropertyCount() { 
     // TODO Auto-generated method stub 
     return 9; 
    } 

    public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) { 
     // TODO Auto-generated method stub 
     switch(index) 
     { 
     case 0: 
      info.type = PropertyInfo.STRING_CLASS; 
      info.name = "CheckOutPlanned"; 
      break; 
     case 1: 
      info.type = PropertyInfo.STRING_CLASS; 
      info.name = "CurrentStatus"; 
      break; 
     case 2: 
      info.type = PropertyInfo.STRING_CLASS; 
      info.name = "FullName"; 
      break; 
     case 3: 
      info.type = PropertyInfo.STRING_CLASS; 
      info.name = "ID"; 
      break; 
     case 4: 
      info.type = PropertyInfo.STRING_CLASS; 
      info.name = "KindergardenID"; 
      break; 
     case 5: 
      info.type = PropertyInfo.STRING_CLASS; 
      info.name = "URL"; 
      break; 
     case 6: 
      info.type = PropertyInfo.STRING_CLASS; 
      info.name = "PickUpBy"; 
      break; 
     case 7: 
      info.type = PropertyInfo.STRING_CLASS; 
      info.name = "PickUpWithKidID"; 
      break; 
     case 8: 
      info.type = PropertyInfo.STRING_CLASS; 
      info.name = "PickUpWithKidName"; 
      break; 
     default: 
      break; 
     } 
    } 

    public void setProperty(int index, Object value) { 
     // TODO Auto-generated method stub 
     switch(index) 
     { 
     case 0: 
      CheckOutPlanned = value.toString(); 
      break; 
     case 1: 
      CurrentStatus = value.toString(); 
      break; 
     case 2: 
      FullName = value.toString(); 
      break; 
     case 3: 
      ID = value.toString(); 
      break; 
     case 4: 
      KindergardenID = value.toString(); 
      break; 
     case 5: 
      URL = value.toString(); 
      break; 
     case 6: 
      PickUpBy = value.toString(); 
      break; 
     case 7: 
      PickUpWithKidID = value.toString(); 
      break; 
     case 8: 
      PickUpWithKidName = value.toString(); 
      break; 
     default: 
      break; 
     } 
    } 

} 

ここで、クラス内のオブジェクトの配列を使用するにはどうすればよいですか?

私はこのような何かを行う必要があることを、どこかで見た:

ArrayList<ChildStatus> myChild = new ArrayList<ChildStatus>(); 
myChild.add(new ChildStatus()); 
myChild.get(0).?? 

しかし、私は、私はので、ここでいくつか間違った方向にオフかもしれないと思う。私の場合はそう

ArrayList<MyClass> myList = new ArrayList<MyClass>(); 

myList.add(new MyClass()); 

myList.get(0).myMethodFromMyClass(); 

を.addと私は新しいオブジェクトを追加しているように聞こえ、私は私のWeb呼び出しで取得したものを取得しない...

iOSで私は通常使用します:

01オブジェクトの配列からオブジェクトを取得するための
Status *theStatus = [statusConnection.statusArray objectAtIndex:i]; 

が、私は、Androidにかなり新たなんだ...

私は本当にあなたが私を与えることができます任意の助けをいただければ幸いです!

+0

pls。参照リンク[http://stackoverflow.com/questions/19198017/pass-arraylist-data-into-soap-web-service-in-android](http://stackoverflow.com/questions/19198017/pass-arraylist-どのように私はアンドロイドでSOAPサービスに配列データを渡すことができますか? –

答えて

0

あなたが本当にやりたいことを理解するのはちょっと難しいことです。

// Get rid of the table 
REMOVE ChildStatus[] children = new ChildStatus[count]; 

// Create the ArrayList 
ArrayList<ChildStatus> myChild = new ArrayList<ChildStatus>(); 

for (int i = 0; i < count; i++) 
{ 
    ChildStatus childStatus = new ChildStatus(); 

    ... 
    HERE YOU POPULATE YOUR childStatus OBJECT WITH THE SOAPOBJECT 
    ... 

    // Add objects built from SOAPObject to the ArrayList 
    myChild.add(childStatus); 

    // The table is of no matter here 
    REMOVE children[i] = childStatus; 
} 

// Use inner methods from an element of the ArrayList (here the number of properties for the first element) 
myChild.get(0).getPropertyCount() 

これはあなたが探していたものではありません場合、私はあなたが求めていた質問、申し訳ありませんでmisleadedされている場合があります。

+0

ああ、私はこの日の後半に解決策を見つけました。それはあなたがここに示唆しているのと似たアプローチです:)しかし、感謝します。 – user1368800