[英]How to get values from soapobject which is coming from server
I am getting a response from the server while doing soap parsing using Ksoap parser. 使用Ksoap解析器进行Soap解析时,我从服务器得到响应。 I want to get specific values from object attributes.
我想从对象属性中获取特定值。 I am using a magento method catalogCategoryInfo and now want to get the children property separately.
我正在使用magento方法catalogCategoryInfo,现在想单独获取children属性。
Here I am getting catalogCategoryInfo: 在这里,我得到catalogCategoryInfo:
request = new SoapObject(NAMESPACE, "catalogCategoryInfo");
request.addProperty("sessionId",sessionId );
request.addProperty("categoryId","2" );
env.setOutputSoapObject(request);
androidHttpTransport.call("", env);
result = (JSONObject)env.getResponse();
System.out.println("%%%%%%%%%%%%%%"+result);
and output is: 输出为:
catalogCategoryInfo{category_id=2; is_active=1; position=1; level=1; parent_id=1; all_children=2,400,407,408,410,402,411,420,421,422,424,425,426,428,430,431,432,433,474,475,526,404,429,444,445,446,447,448,449,450,451,453,454,455,456,457,458,459,460,461,405,465,466,467,468,406,476,478,479,480,481,512,513,514,516,517,518,519,520,521,522,523,524,525,527,528,533,535,537,539,540,544; children=400,402,404,405,406,512,527; created_at=2016-02-04 05:39:36; updated_at=2016-02-06 07:28:28; name=Default Category; url_key=default-category; path=1/2; url_path=/default-category; children_count=71; display_mode=PRODUCTS; is_anchor=0; available_sort_by=ArrayOfString{}; default_sort_by=position; }
Now I want to get only the children=400,402,404,405,406,512,527;
现在我只想得到
children=400,402,404,405,406,512,527;
property. 属性。
Get Values from JSON object using key values 1. First get parent object JSONObject resObj=result.getJSONObject("catalogCategoryInfo"); 使用键值从JSON对象获取值1.首先获取父对象JSONObject resObj = result.getJSONObject(“ catalogCategoryInfo”); 2. get values from object, its look not formatted json
2.从对象获取值,其外观未格式化json
children=400,402,404,405,406,512,527
children is key, if you want one by one value ask Backend return as JSON Array. children是关键,如果您想要一个一的值,请要求Backend作为JSON数组返回。
if children is String
string value=resOnj.getString("children");
else children is int
int value=resOnj.getInt("children");
I found my solution. 我找到了解决方案。 we can achieve it by using following code: //fetch category information request = new SoapObject(NAMESPACE, "catalogCategoryInfo");
我们可以使用以下代码来实现它://获取类别信息request = new SoapObject(NAMESPACE,“ catalogCategoryInfo”);
request.addProperty("sessionId ",sessionId );
request.addProperty("categoryId","2");
env.setOutputSoapObject(request);
androidHttpTransport.call("urn:Magento/catalogCategoryInfo",env);
SoapObject response = (SoapObject) env.getResponse();
Object children = (Object)response.getProperty(6);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.