解决android.view.View android.view.ViewStub.inflate()' on a null object reference
异常
解决:就是ViewStub只能调用inflate一次,代码如下:
View viewStub = findViewById(R.id.grey_mask_container);
viewStub.inflate();
修改为
View viewStub = findViewById(R.id.grey_mask_container);
if(viewStub != null){
viewStub.inflate();
}
服务器接收的Json数据有问题
错误写法
try{
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
jsonObject.put("goodsId", "123456");
jsonArray.put(jsonObject);
JSONObject paramsObj = new JSONObject();
paramsObj.put("goods", jsonArray.toString());
Log.d(TAG, "result: "+paramsObj);
}catch (Exception e){
e.printStackTrace();
}
输出:
result:{"goods":"[{\"goodsId\":\"123456\"}]"}
正确写法
try{
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
jsonObject.put("goodsId", "123456");
jsonArray.put(jsonObject);
JSONObject paramsObj = new JSONObject();
paramsObj.put("goods", jsonArray);
Log.d(TAG, "setupView: "+paramsObj);
}catch (Exception e){
e.printStackTrace();
}
输出:
result:{"goods":[{"goodsId":"123456"}]}
结论:JSONArray调用了toString会导致服务器接收的数据有""