我正在尝试使用 json.put() 将数据从 json 发送到输出下方的等效 php 格式;
Array
(
[node] => Array
(
[name] => admin
[type] => mobile_content
[language] => und
[title] => re resss re@fffd.com
[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] => re@fffd.com
)
)
)
[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 发送到服务器的正确方法吗?