Android CouchDB {"error":"bad_request","reason":"invalid_json"}

Android CouchDB {"error":"bad_request","reason":"invalid_json"}

尝试在我的 IrisCouch 数据库中创建新文档时,我总是收到以下错误: {"error":"bad_request","reason":"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 of "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 验证器对其进行了测试。

我能做什么?提前致谢!

也许 unicode 上标 2 (²) 在困扰它? 不确定这个 HttpPost 是哪个库,但看起来很像 HttpWebRequest,所以尝试这样设置你的 header:

httpPost.setHeader("Content-type", "application/json charset=utf-8");

也可能是 HttpPost class 没有正确编码字符串。 (我还没有把它粘贴到我的 Visual studio 中,所以只是在黑暗中拍摄)