我们正在开发一个 iPhone 应用程序,它将用户所在位置的 json 字符串发送到部署在 Google 应用程序引擎上的 Web 应用程序 (JAVA)。我们使用 htpp 请求来发送这些字符串。我们的问题是字符串有时很大,这需要很长时间。还有其他方法吗?
最佳答案
您可以压缩 JSON。这是 GAE 的代码片段:
JSONObject json = new JSONObject(uncompress(Base64.decode(encodedJSONData)));
这是解压缩方法:
protected String uncompress(byte[] compressedData) throws IOException {
StringBuffer data = new StringBuffer();
GZIPInputStream stream = new GZIPInputStream(new ByteArrayInputStream(compressedData));
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
String line;
while ((line = br.readLine()) != null) {
data.append(line);
}
return data.toString();
}
关于ios - 将 json 对象从 iphone 发送到 java servlet 的时间太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8909761/