java.lang.string无法转换为JSONarray

时间:2018-10-08 10:21:52

标签: android

我必须尝试将字符串转换为json数组。但仍然跟随错误

.addBodyParameter("checkbox1", String.valueOf(s.getCheckbox1()))

我使用该代码从字符串转换为jsonarray
这是我的完整代码,

public void add(Spacecraft s, final View...inputViews)
{
    if(s==null)
    {
        Toast.makeText(c, "No Data To Save", Toast.LENGTH_SHORT).show();
    }
    else
    {
        AndroidNetworking.post(DATA_INSERT_URL)
                .addBodyParameter("action","save")
                .addBodyParameter("checkbox1", String.valueOf(s.getCheckbox1()))
                .setTag("TAG_ADD")
                .build()
                .getAsJSONArray(new JSONArrayRequestListener() {
                    @Override
                    public void onResponse(JSONArray response) {

                        if(response != null)
                            try
                            {
                                String responseString = response.get(0).toString();
                                Toast.makeText(c, "PHP SERVER RESPONSE : " + responseString, Toast.LENGTH_SHORT).show();


                            } catch (JSONException e) {
                                e.printStackTrace();
                                Toast.makeText(c, "GOOD RESPONSE BUT JAVA CAN'T PARSE JSON IT RECEIVED : "+e.getMessage(), Toast.LENGTH_SHORT).show();
                            }

                    }

                    @Override
                    public void onError(ANError anError) {
                        Toast.makeText(c, "UNSUCCESSFUL :  ERROR IS : "+anError.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });
    }
}

1 个答案:

答案 0 :(得分:1)

String.valueOf(s.getCheckbox1())对我来说毫无意义。也许您想使用s.getCheckbox1().isChecked()

检查状态