我想使用Loop j将字符串数组和对象发布到服务器

时间:2017-09-01 16:46:55

标签: android post loopj

每次收到错误" BAD请求"。我试图发布像这样的json

的数据
{
"name":"testOne",
"location": "['one','two','three']"
}

这是我的代码

    AsyncHttpClient client = new AsyncHttpClient();
    String someData="{\"name\":\"testOne\",\"location\": \"['ne','two','three']\"}";
    ByteArrayEntity be = new ByteArrayEntity(someData.toString().getBytes());
    client.post(MainActivity.this, "http://impero-dannyfast.rhcloud.com/api/agents", be, "application/json", new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {

            Toast.makeText(MainActivity.this, "Succ", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

            Toast.makeText(MainActivity.this, "fail"+statusCode, Toast.LENGTH_SHORT).show();

        }

        });

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

{
"name":"testOne",
"location": ["one","two","three"]
}

尝试像这样发送