我正在使用凌空进行解析。这是我作为邮寄请求传递的参数。
{
"typeName": "MANUFACTURER",
"typeId": 22,
"tempId": 308,
"sortBy": "productname",
"sortOrder": "desc",
"filter":[
{
"filterId":101,
"typeName":"CAT_ID",
"filterId":102,
"typeName":"CAT_ID"
}
]
}
现在的问题是,如果我要添加tempId,那么我没有得到回应。但如果我删除tempId我得到适当的回应。我用邮递员和其他工具检查我的网络服务。 Webservice没有问题。任何人都可以帮我解决这个问题吗?没有任何崩溃日志。
public void Productlistcall()
{
showpDialog();
/* Map<String, String> jsonParams = new HashMap<String, String>();
jsonParams.put("typeName", "MANUFACTURER");
jsonParams.put("typeId", "22");
jsonParams.put("sortBy", "productname");
jsonParams.put("sortOrder", "desc");*/
Map<String, String> jsonParams = new HashMap<String, String>();
/* object.put("typeName","MANUFACTURER");
object.put("typeId","22");
object.put("tempId","308");
object.put("sortBy","productname");
object.put("sortOrder","desc");*/
if(filter_items!=null)
{
jsonParams.put("typeName", "MANUFACTURER");
jsonParams.put("typeId", "22");
jsonParams.put("tempId","308");
jsonParams.put("sortBy", "productname");
jsonParams.put("sortOrder", "desc");
JSONArray array=new JSONArray();
JSONObject obj=new JSONObject();
String filtersepid = null;
System.out.println("FILTER LIST DATA IS NOT NULL");
array.put(obj);
jsonParams.put("filter",obj.toString());
for(int i=0;i<filter_items.size();i++)
{
filtersepid=filter_items.get(i);
System.out.println("filtersepid"+filtersepid);
try {
obj.put("filterId",filter_items.get(i));
} catch (JSONException e) {
e.printStackTrace();
}
try {
obj.put("typeName","CAT_ID");
} catch (JSONException e) {
e.printStackTrace();
}
}
}
else
{
jsonParams.put("typeName", "MANUFACTURER");
jsonParams.put("typeId", "22");
jsonParams.put("tempId","308");
jsonParams.put("sortBy", "productname");
jsonParams.put("sortOrder", "desc");
System.out.println("FILTER LIST DATA IS NULL");
}
System.out.println("DRAWER PARAMS" + jsonParams);
JsonObjectRequest postRequest = new JsonObjectRequest( Request.Method.POST, url,
new JSONObject(jsonParams),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
System.out.println("response Productlist-->> " + response.toString());
productlist = new ArrayList<ProductListModel>();
ch_list = new ArrayList<String>();
color_list=new ArrayList<String>();
try {
JSONObject drawerdatas = (JSONObject) response.getJSONObject("Data");
JSONArray products=drawerdatas.getJSONArray("products");
JSONArray filtersdata=drawerdatas.getJSONArray("filtersList");
JSONArray sortingdata=drawerdatas.getJSONArray("sortingList");
String headerText=drawerdatas.getString("headerText");
String productCount=drawerdatas.getString("productCount");
productlist = new ArrayList<ProductListModel>();
for (int j = 0; j < products.length(); j++) {
JSONObject jo = products.getJSONObject(j);
ProductListModel ch = new ProductListModel();
ch.setProduct_Id(jo.getString("productId"));
ch.setProduct_Name(jo.getString("productName"));
ch.setProduct_Img(jo.getString("productImage"));
ch.setProduct_Price(jo.getString("productSP"));
ch.setProduct_RatingImgPath(jo.getString("productRatingImage"));
ch.setProduct_pRating(jo.getString("productRatingCount"));
/* if(jo.getString("productOfferText").equals("null"))
{
ch_list.add(" ");
System.out.println("text is null");
}
else
{
JSONArray txtdetail=jo.getJSONArray("productOfferText");
System.out.println("txtdetailarray"+txtdetail);
StringBuilder sb = new StringBuilder();
for(int k=0;k<txtdetail.length();k++)
{
JSONObject jdetail=txtdetail.getJSONObject(k);
disptext=jdetail.getString("displayText");
dispclr=jdetail.getString("displayColor");
//ch_list.add(disptext);
color_list.add(dispclr);
// sb.append(disptext);
System.out.println("clr" + color_list.get(k).toString());
colors=color_list.get(k);
String string = colors;
String[] parts = string.split("\\*");
int part1 = Integer.parseInt(parts[0]);
int part2 = Integer.parseInt(parts[1]);
int part3 = Integer.parseInt(parts[2]);
hex = String.format("#%02X%02X%02X", part1, part2, part3);
sb.append(addColor(disptext.trim(), hex));
System.out.println("hexa"+hex);
}
detailtext=sb.toString();
ch_list.add(detailtext);
System.out.println("Output: " + sb.toString().replaceAll("\\\\n", "\n"));
}
*/
productlist.add(ch);
}
filterlist = new ArrayList<ModelUser>();
for(int c=0;c<filtersdata.length();c++)
{
JSONObject jo = filtersdata.getJSONObject(c);
JSONArray filters=jo.getJSONArray("filters");
String groupName=jo.getString("groupName");
String typeName=jo.getString("typeName");
for(int g=0;g<filters.length();g++)
{
JSONObject jos = filters.getJSONObject(g);
ModelUser flm = new ModelUser();
flm.setId(Integer.parseInt(jos.getString("filterId")));
flm.setUserName(jos.getString("filterName"));
filterlist.add(flm);
}
}
sortlist=new ArrayList<SortingListModel>();
for(int d=0;d<sortingdata.length();d++)
{
JSONObject jo = sortingdata.getJSONObject(d);
SortingListModel scm = new SortingListModel();
scm.setSort_text(jo.getString("text"));
scm.setSort_value(jo.getString("value"));
sortlist.add(scm);
}
rvAdapter = new RecyclerViewAdapter(getActivity(),productlist);
recyclerView.setAdapter(rvAdapter);
pronames.setText(headerText);
if(productlist.size() < 2)
{
procounts.setText(String.valueOf(productlist.size() + " Product"));
}
else
{
procounts.setText(String.valueOf(productlist.size() + " Products"));
}
} catch (JSONException e) {
e.printStackTrace();
}
hidepDialog();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//Handle Error
hidepDialog();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("API_Version","1.0");
headers.put("deviceName","ANDROID");
return headers;
}
};
Volley.newRequestQueue(getActivity()).add(postRequest);
}
答案 0 :(得分:0)
您正在使用此
jsonParams.put( “tempId”, “308”);
试试这个
jsonParams.put( “cityId”, “308”);
答案 1 :(得分:0)
重新排列并在if else条件下使用以下代码。你没有按正确的顺序生成json
if(filter_items!=null)
{
jsonParams.put("typeName", "MANUFACTURER");
jsonParams.put("typeId", "22");
jsonParams.put("tempId","308");
jsonParams.put("sortBy", "productname");
jsonParams.put("sortOrder", "desc");
JSONArray array=new JSONArray();
String filtersepid = null;
System.out.println("FILTER LIST DATA IS NOT NULL");
for(int i=0;i<filter_items.size();i++)
{
JSONObject obj=new JSONObject();
filtersepid=filter_items.get(i);
System.out.println("filtersepid"+filtersepid);
try {
obj.put("filterId",filter_items.get(i));
} catch (JSONException e) {
e.printStackTrace();
}
try {
obj.put("typeName","CAT_ID");
} catch (JSONException e) {
e.printStackTrace();
}
array.put(obj);
}
jsonParams.put("filter",array);
}
else
{
jsonParams.put("typeName", "MANUFACTURER");
jsonParams.put("typeId", "22");
jsonParams.put("tempId","308");
jsonParams.put("sortBy", "productname");
jsonParams.put("sortOrder", "desc");
System.out.println("FILTER LIST DATA IS NULL");
}
答案 2 :(得分:0)
我用
解决了这个问题compile 'com.android.volley:volley:1.0.0'
我正在使用这个
compile 'com.mcxiaoke.volley:library:1.0.19'