簡體   English   中英

如何解析Java中的對象列表

[英]How to Parse List of Object in Java

我想解析idKeys1並從idKeys1獲得屬性ID(Pds AttributeId)和屬性Value(value)。 我不確定解析它的最佳方法是什么,因為它是PDSAttribute的列表。

List<PdsAttribute> idKeys1 = m_pdssmartclient.release(PersistenceEnum.COMMIT, false);
Iterator<PdsAttribute> i = idKeys1.iterator();
  while (i.hasNext()) {
                    String parse = String.valueOf(i.next());
                    System.out.println(i.next());
                      }

idKeys1的示例輸出是:-

[Pds Attribute: 
Pds AttributeId = 20000
value = 0
Attribute Status = 
Status Code = 0
Status = NOT_PROCESSED
Status message = null

, Pds Attribute: 
Pds AttributeId = 20002
value = -1
Attribute Status = 
Status Code = 0
Status = NOT_PROCESSED
Status message = null

, Pds Attribute: 
Pds AttributeId = 20004
value = -9223372036854775808
Attribute Status = 
Status Code = 0
Status = SUCCESS
Status message = null

, Pds Attribute: 
Pds AttributeId = 248
value = 1906e3551370af60d5b48854fffffffe
Attribute Status = 
Status Code = 0
Status = NOT_PROCESSED
Status message = null

, Pds Attribute: 
Pds AttributeId = 330
value = null
Attribute Status = 
Status Code = 0
Status = NOT_PROCESSED
Status message = null

, Pds Attribute: 
Pds AttributeId = 202
value = 1906e1611370af60d5b48854ffffffff
Attribute Status = 
Status Code = 0
Status = SUCCESS
Status message = null

, Pds Attribute: 
Pds AttributeId = 331
value = null
Attribute Status = 
Status Code = 0
Status = NOT_PROCESSED
Status message = null

, Pds Attribute: 
Pds AttributeId = 347
value = 1906e5a11370af60d5b48854fffffffd
Attribute Status = 
Status Code = 0
Status = NOT_PROCESSED
Status message = null

, Pds Attribute: 
Pds AttributeId = 332
value = 4fa813bc.0.1.8.9.5.0.1
Attribute Status = 
Status Code = 0
Status = NOT_PROCESSED
Status message = null

, Pds Attribute: 
Pds AttributeId = 12
value = 1002491107
Attribute Status = 
Status Code = 0
Status = NOT_PROCESSED
Status message = null

, Pds Attribute: 
Pds AttributeId = 333
value = 4fa813bc.0.1.7.8.0.0.1
Attribute Status = 
Status Code = 0
Status = NOT_PROCESSED
Status message = null

]

那怎么了

        while (i.hasNext()) {
            PdsAttribute attr = (PdsAttribute) (i.next());
            String attrId = String.valueOf(attr.getAttributeId);
            String attrValue = String.valueOf(attr.getValue());
        }

當然,這假定您具有PdsAttributeId和PdsAttribute類中的值的適當訪問器。 如果沒有,您應該真正考慮添加一些封裝它的成員。

如果PdsAttributeIdvaluePdsAttribute類中的字段,並且在其字段上定義了setter方法,則在迭代中進行以下更改

while ( i.hasNext() ) {  
    PdsAttribute pdsAttribute = ( PdsAttribute ) i.next();  
    String pdsAttributeId = String.valueOf( pdsAttribute.getPdsAttributeId() );  
    String pdsAttributeValue = String.valueOf( pdsAttribute.getValue() );  

    // now use these values as required  
} // while

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM