我想解析idKeys1并从idKeys1获取属性ID(Pds AttributeId)和属性值(值)。我不确定解析它的最佳方法是什么,因为它是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
]
答案 0 :(得分:0)
所以
错了 while (i.hasNext()) {
PdsAttribute attr = (PdsAttribute) (i.next());
String attrId = String.valueOf(attr.getAttributeId);
String attrValue = String.valueOf(attr.getValue());
}
当然,假设您在PdsAttribute类中拥有PdsAttributeId和值的适当访问器。如果没有,你应该考虑添加一些来封装它的成员。
答案 1 :(得分:0)
如果PdsAttributeId
和value
是PdsAttribute
类中的字段,并且在其字段中定义了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