これの具体的な数は怒っ私を運転しているWebサービスに渡されます - そしてほとんどの部分は、我々は問題ありませんが、私たちは」NULL JSONモデルは、特殊文字
private String callWebService(String JSONModel, URL url, int appId) throws Exception {
int connTimeout = 5000;
System.setProperty("http.keepAlive", "false");
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) url.openConnection();
//Populate Header
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
conn.setChunkedStreamingMode(0);
conn.setConnectTimeout(connTimeout);
conn.setReadTimeout(connTimeout);
if (JSONModel != null) {
conn.setRequestProperty("Content-Length", String.valueOf(JSONModel.length()));
conn.setDoInput(true);
OutputStream stream = new BufferedOutputStream(conn.getOutputStream());
stream.write(JSONModel.getBytes());
stream.flush();
stream.close();
} else {
conn.setDoOutput(true);
conn.setChunkedStreamingMode(0);
conn.setRequestProperty("Content-Length", "0");
}
conn.connect();
BufferedReader inputStreamReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder returnStringBuilder = new StringBuilder();
String streamString;
while ((streamString = inputStreamReader.readLine()) != null) {
returnStringBuilder.append(streamString);
}
inputStreamReader.close();
return returnStringBuilder.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
throw e;
} catch (SocketTimeoutException e) {
throw e;
} catch (SSLHandshakeException e) {
throw e;
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw e;
} finally {
conn.disconnect();
}
return null;
}
WebServiceがこのモデルを受信し、離れて行くと、いくつかのバックエンドのDBのものを行う必要があります。このメソッドを使用して交流#のWebサービス私は複製することができますが修正することができないいくつかのバグレポートを持っていました。
モデルの「ジョブ」リストには、「completeNotes」という文字列プロパティがあります。 completeNotesが4つの "£"記号で埋められても、すべてが動作しますが、5つの "£"記号がある場合、受信するWebサービスモデルはNULLになり、Webサービスで例外がスローされたことがわかります:
Exception thrown: 'Newtonsoft.Json.JsonReaderException' in Newtonsoft.Json.dll
Additional information: Invalid character after parsing property name. Expected ':' but got: . Path 'Jobs', line 1, position 1585.
ちょうど副次的なものとして、これは2€記号しか許さないことを除けば€記号でも起こります。同じことをします - NULLモデルを通す - シンボルは連続している必要はありません
私はその非常に長いと全体JSONは表示されません..しかし、私は話すプロパティがそれに次のように設定されている次のいずれか
"completeNotes":"£££££"
なぜこのようなことが起こっているのか誰にでも分かっています。私はエンコーディング(UTF-8に設定しています)を使いこなそうとしましたが、これは違いはありません。
はい..私は、あまりにもUTF-8に書き込むためのOutputStreamを余儀なくされた。 stream.write(JSONModel文字セットが非難された場合、私は1つの "£"記号を受け入れないだろうと思っていましたが、それは4つの文字を受け入れることになりました(^ _ ^;) ..ちょうど5ではない! –
この解決策を試してみてください。http://stackoverflow.com/a/29903374/1027550 – MRodrigues