我想从json发送数据到等价的php格式输出使用json.put();使用httpclient发送Json objet到drupal Android
Array
(
[node] => Array
(
[name] => admin
[type] => mobile_content
[language] => und
[title] => re resss [email protected]
[field_one] => Array
(
[und] => Array
(
[0] => Array
(
[value] => re
)
)
)
[field_prenom] => Array
(
[und] => Array
(
[0] => Array
(
[value] => resss
)
)
)
[field_addr] => Array
(
[und] => Array
(
[0] => Array
(
[value] => [email protected]
)
)
)
[field_email] => Array
(
[und] => Array
(
[0] => Array
(
[value] => 01/01/1913
)
)
)
[field_collectif] => Array
(
[und] => Array
(
[0] => Array
(
[value] => 1
)
)
)
[field_bach] => Array
(
[und] => Array
(
[0] => Array
(
[value] => 0
)
)
)
[field_mc_rec] => Array
(
[und] => Array
(
[0] => Array
(
[value] => 1
)
)
)
[field_photo] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 1778
)
)
)
)
)
我的问题是我无法正确获取格式。
i created my json object
try {
JSONObject json = new JSONObject();
然后把使用节点
json.put("node[type]","type");
然后最后JSON输出发送到
DefaultHttpClient httpClient = new DefaultHttpClient();
ResponseHandler<String> resonseHandler = new BasicResponseHandler();
HttpPost postMethod = new HttpPost(path);
String authorizationString = "Basic " + Base64.encodeToString(
("uname" + ":" + "pword").getBytes(),
Base64.NO_WRAP);
postMethod.setHeader("Authorization", authorizationString);
postMethod.setHeader("Content-Type","application/x-www-form-urlencoded");
postMethod.setHeader("Accept", "application/json");
postMethod.setEntity(new ByteArrayEntity(params.toString().getBytes("UTF8")));
String response = httpClient.execute(postMethod,resonseHandler);
if (response.equals("[]")) //empty
return null;
else
{
System.out.println("response :" + response);
JSONObject jObject=new JSONObject(response);
return jObject;
}
我的错误日志显示
org.apache.http.client.HttpResponseException: Not Acceptable: Node type is required
,但是,从服务器端我没有显示日志。这意味着json对象没有被发送。这很奇怪。请注意,我正在发送到Drupal。请帮助。这是发送文本格式JSON到服务器的正确方法。
给出一些更多异常日志行。它似乎在Android方面异常,但不是在服务器上,但需要更多的异常日志行。 –