Android 我试图使用循环j将一个json字符串发布到服务器中,但得到了一个错误
我试图发布请求,如下面的响应,并得到错误{“消息”:“模型没有字段‘对象’}Android 我试图使用循环j将一个json字符串发布到服务器中,但得到了一个错误,android,json,Android,Json,我试图发布请求,如下面的响应,并得到错误{“消息”:“模型没有字段‘对象’} { "num_results": 20, "objects": [ { "agent": "LAPTOP_01", "bluetooth_id": "33:22:55:44:FF:AA", "created_at": "2017-09-05T18:02:00", "device_name": "android_name", "id":
{
"num_results": 20,
"objects": [
{
"agent": "LAPTOP_01",
"bluetooth_id": "33:22:55:44:FF:AA",
"created_at": "2017-09-05T18:02:00",
"device_name": "android_name",
"id": 1,
"location": "gps_location_info",
"name": "LAPTOP_01",
"raw": "['additional','info','goes','here']"
}
],
"page": 1,
"total_pages": 2
}
这是我发布json字符串的代码
AsyncHttpClient client = new AsyncHttpClient();
String someData="{\"objects\": [{\"agent\": \"tsetLappy\", \"bluetooth_id\": \"33:25:55:44:FF:AA\", \"created_at\": \"2017-09-05:02:00\", \"device_name\": \"android_test\", \"location\": \"gps_info\", \"name\": \"testlappy\", \"raw\": \"['addl','inf','ges','hee']\"}]}";
StringEntity entity = new StringEntity(someData);
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);
status.setText("Status: Posted Successfully!");
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
super.onFailure(statusCode, headers, throwable, errorResponse);
status.setText("Status: Error in Sending Data!"+errorResponse);
}
});
如果您知道此错误,请花一分钟来帮助。。。
谢谢试试这个:
ByteArrayEntity entity = null;
try {
String someData="{\"objects\": [{\"agent\": \"tsetLappy\", \"bluetooth_id\": \"33:25:55:44:FF:AA\", \"created_at\": \"2017-09-05:02:00\", \"device_name\": \"android_test\", \"location\": \"gps_info\", \"name\": \"testlappy\", \"raw\": \"['addl','inf','ges','hee']\"}]}";
entity = new ByteArrayEntity(someData.getBytes("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
}
client.post(context, requestUrl, entity, "application/json", new JsonHttpResponseHandler() {
}
如果上述方法不适用于您,请尝试从json字符串中删除所有“\”
,尝试以下方法:
ByteArrayEntity entity = null;
try {
String someData="{\"objects\": [{\"agent\": \"tsetLappy\", \"bluetooth_id\": \"33:25:55:44:FF:AA\", \"created_at\": \"2017-09-05:02:00\", \"device_name\": \"android_test\", \"location\": \"gps_info\", \"name\": \"testlappy\", \"raw\": \"['addl','inf','ges','hee']\"}]}";
entity = new ByteArrayEntity(someData.getBytes("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
}
client.post(context, requestUrl, entity, "application/json", new JsonHttpResponseHandler() {
}
如果上述方法不适用于您,请尝试从json字符串中删除所有
“\”
,检查邮递员的json Post请求,如果您收到相同的错误,请向api开发人员询问确切的json Post格式,或告诉他们检查他从Post后端得到的内容。因为此错误消息是从服务器端显示的 检查Postman上的json Post请求,如果您收到相同的错误,请向api开发人员询问确切的json Post格式,或者告诉他们检查他从Post后端得到的内容。因为此错误消息是从服务器端显示的 尝试使用jobj.putjobj.put???。@Arslan Ali请创建对象pojo类。尝试使用jobj.putjobj.put???。@Arslan Ali请创建对象pojo类。让我检查此相同错误发生模型没有字段“对象”让我检查此相同错误发生模型没有字段“对象”