我想解析我的Ksoap响应数组,但没有得到它
调试app时响应:
events_data {
events = [events {
groom = sanskaar;
bride = saumya;
event_name = wedding;
venue = New Delhi;
event_date = Tuesday April 14, 2014;
},
events {
groom = sanskaar;
bride = saumya;
event_name = hzbrgbj;
venue = New Delhi;
event_date = Tuesday April 14, 2014;
},
events {
groom = sanskaar;
bride = saumya;
event_name = wedding;
venue = New Delhi;
event_date = Tuesday April 14, 2014;
}
];
}
用于解析响应的代码:
SoapObject response = (SoapObject) envelope.getResponse();
//SoapObject response = (SoapObject) envelope.bodyIn;
System.out.print(response);
int count = response.getPropertyCount();
System.out.print(count);
for(int i=0;i<response.getPropertyCount();i++){
Object property = response.getProperty(i);
if(property instanceof SoapObject){
SoapObject final_object = (SoapObject) property;
//Parsing response data
Event_data.put("groom", final_object.getProperty("groom").toString());
System.out.print(Event_data);//testing of response data
}
}
(属性instanceof SoapObject)给予false
。代码不解析响应。
虽然我正在使用相同的活动代码解析此后续响应,但其工作正常:
data {
user = user {
id = 39;
user_name = ;
email = ;
phone = 7827701616;
address = ;
url = ;
user_role = 1;
plan = 1;
verification_pin = 18053;
status = 1;
android_id = 38d23c7201b21f93;
};
}
帮助我。
答案 0 :(得分:0)
试试这个代码伙伴:
SoapObject response = (SoapObject) envelope.getResponse();
//SoapObject response = (SoapObject) envelope.bodyIn;
System.out.print(response);
int count = response.getPropertyCount();
System.out.print(count);
for(int i=0;i<response.getPropertyCount();i++){
Object property = response.getProperty(i);
if(property instanceof SoapObject){
SoapObject final_object = (SoapObject) property;
for(int j=0; j<final_object.getPropertyCount();j++){
Object final_property = final_object.getProperty(j);
if(final_property instanceof SoapObject){
SoapObject array_object = (SoapObject) final_property;
//Parsing response data
Event_data.put("groom",array_object.getProperty("groom").toString());
}
}
System.out.print(Event_data);//testing of response data
}
}
答案 1 :(得分:0)
阅读本文:
How to parse this type soap array response in android
根据其他帖子,回复应如下所示,请检查,
events_data {
events = events {
groom = sanskaar;
bride = saumya;
event_name = wedding;
venue = New Delhi;
event_date = Tuesday April 14, 2014;
};
events {
groom = sanskaar;
bride = saumya;
event_name = hzbrgbj;
venue = New Delhi;
event_date = Tuesday April 14, 2014;
};
events {
groom = sanskaar;
bride = saumya;
event_name = wedding;
venue = New Delhi;
event_date = Tuesday April 14, 2014;
};
}
答案 2 :(得分:0)
我使用VECTOR
<强>代码:强>
ht.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
for(int i=0;i<response.getPropertyCount();i++){
Vector resV = (Vector)response.getProperty(i);
int resVlenght = resV.size();
for(int count = 0;count<resVlenght;count++)
{
HashMap<String,String> value = new HashMap<String,String>();
String n = resV.elementAt(count).toString();
SoapObject p = (SoapObject)resV.elementAt(count);
System.out.print(n);
String groom= p.getProperty("groom").toString();
}
}