我想使用循环j将此json字符串发布到服务器

时间:2017-09-01 18:56:58

标签: android json

以下是我想在服务器上发布的内容

{

"name":"testOne",
"location": "['one','two','three']"

}

以下是我总是收到此错误的代码{"message":"IntegrityError"}

AsyncHttpClient client = new AsyncHttpClient();

    String someData="{\"name\":\"testOne\",\"location\": \"[\'ne\',\'two\',\'three\']\"}";


    StringEntity entity = new StringEntity(someData);
    Log.e("Json", String.valueOf(entity));
    client.post(MainActivity.this, "http://impero-dannyfast.rhcloud.com/api/agents", entity, "application/json", new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);


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


            }

            @Override
            public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
                super.onFailure(statusCode, headers, throwable, errorResponse);
                Toast.makeText(MainActivity.this, "fail"+errorResponse, Toast.LENGTH_SHORT).show();

                Log.e("Tag:", String.valueOf(errorResponse));

            }
        });

    }

1 个答案:

答案 0 :(得分:0)

Django服务器中捕获到异常。

错误的定义:

  

当数据库的关系完整性出现时引发异常   影响,例如外键检查失败,重复密钥等

来源:https://code.djangoproject.com/wiki/IntegrityError