我在使用Ksoap解析器进行soap解析时从服务器获得响应。我想从对象属性中获取特定值。我正在使用magento方法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);
,输出为:
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; }
现在我想只获得children=400,402,404,405,406,512,527;
属性。
答案 0 :(得分:1)
使用键值从JSON对象获取值 1.首先获取父对象 JSONObject resObj = result.getJSONObject(" catalogCategoryInfo"); 2.从对象获取值,它看起来没有格式化json
children=400,402,404,405,406,512,527
子项是关键,如果你想逐个值请求Backend返回JSON数组。
if children is String
string value=resOnj.getString("children");
else children is int
int value=resOnj.getInt("children");
答案 1 :(得分:0)
我找到了解决方案。 我们可以使用以下代码实现它: //获取类别信息 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);