Hello Friends我想在soap响应中单独创建值
public class GoldFragment extends Fragment {
int mCurrentPage ;
TextView mTextViewName;
ProgressDialog mProgressDialog;
SoapObject mSoapObjectCompanyDetailResponse;
public final String NAMESPACE = "http://freewebservicesx.com/";
public final String URL = "http://www.freewebservicesx.com/GetGoldPrice.asmx";
public final String SOAP_ACTION_1 = "http://freewebservicesx.com/GetCurrentGoldPrice";
public final String METHOD_NAME_1 = "GetCurrentGoldPrice";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View mView=inflater.inflate(R.layout.activity_main, container, false);
mTextViewName=(TextView)mView.findViewById(R.id.name);
Bundle data = getArguments();
/** Getting integer data of the key current_page from the bundle */
mCurrentPage = data.getInt("current_page", 0);
new GetGoldPrice().execute();
return mView;
}
public class GetGoldPrice extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
mProgressDialog=ProgressDialog.show(getActivity(), "Wait", "Loading");
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME_1);
request.addProperty("UserName","fdsfdsfsdfsd);
request.addProperty("Password","sfsdfdsd");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION_1, envelope);
mSoapObjectCompanyDetailResponse = (SoapObject)envelope.bodyIn;
Object re= null;
re = envelope.getResponse();
Log.i("myApp", mSoapObjectCompanyDetailResponse.toString());
System.out.println("response "+mSoapObjectCompanyDetailResponse.toString());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (mProgressDialog!=null) {
mProgressDialog.dismiss();
}
if (!mSoapObjectCompanyDetailResponse.toString().equalsIgnoreCase("")) {
mTextViewName.setText(mSoapObjectCompanyDetailResponse.getAttribute(0).toString());
}
}
}
}
,我的SOAP响应如下所示
01-11 17:39:35.029: I/System.out(25357): GetCurrentGoldPriceResponse{ GetCurrentGoldPriceResult = anyType { string=1,244.73; string=anyType{}; string=1.33%; }; }
所以我想制作单独的值string = 1,244.73和string = 1.33%,,我怎么能让它明白呢?
答案 0 :(得分:0)
我得到了解决方案,只需在两行中进行更改
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (mProgressDialog!=null) {
mProgressDialog.dismiss();
}
if (!mSoapObjectCompanyDetailResponse.toString().equalsIgnoreCase("")) {
SoapObject root = (SoapObject) mSoapObjectCompanyDetailResponse.getProperty(0);
System.out.println("Price"+root.getProperty(0).toString());
System.out.println("Change"+root.getProperty(2).toString());
}
}