在我的IrisCouch数据库中尝试创建新文档时,我总是遇到以下错误: { “错误”: “BAD_REQUEST”, “理由”: “invalid_json”}
这是我职能的相关部分:
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("https://username.iriscouch.com:6984/mydb");
StringEntity entity = new StringEntity(body);
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse httpResponse = httpClient.execute(httpPost);
System.out.println(httpResponse.toString()) ;
HttpEntity httpEntity = httpResponse.getEntity();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(httpEntity.getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
System.out.println("body: " + body);
} catch (Exception e) {
e.printStackTrace();
}
这是我的System.out“body”:
{"bild1":"","bild2":"","bild3":"","bild4":"","bild5":"","bild6":"","bild7":"","bild8":"","bild9":"","bild10":"","name":"","plz":0,"ort":"","strasse":"","n_koordinate":0,"e_koordinate":0,"beschreibung":"","groesse":"< 50m²","sitzplaetze":"< 50","grillstellen":"1","reservierung":false,"res_name":"","res_tele":"","res_weiteres":"","wc":true,"behindi":false,"dach":true,"kinderfreundl":false,"auto":false,"kinderwagen":false,"einkauf":false,"datum":"2015-07-01-14:12:01:856","bewertung":0,"anz_bewertung":0}
JSON有效。使用jsonlint.com JSON Validator进行测试。
我该怎么办?提前谢谢!
答案 0 :(得分:0)
也许unicode上标2(²)困扰它? 不知道这个HttpPost是哪个库,但看起来很像HttpWebRequest,所以尝试以这种方式设置标题:
/* in the extension */
var description = {};
chrome.tabs.sendMessage(tabs[0].id, {
desc: 'some value'
}, function(response) {
description.value = response.details;
/* do your thing */
});
/* in the content script (your popup) */
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
var desc = request.desc;
sendResponse(desc);
});
也可能是HttpPost类没有正确编码字符串。 (我没有在我的Visual Studio中粘贴它,所以只是在黑暗中拍摄)