我想從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方面異常,但不是在服務器上,但需要更多的異常日誌行。 –