将 json 对象从 iphone 发送到 java servlet 的时间太长

发布于 2024-12-27 10:16:37 字数 136 浏览 1 评论 0原文

我们正在开发一个 iPhone 应用程序,它将用户所在位置的 json 字符串发送到部署在 Google 应用程序引擎上的 Web 应用程序 (JAVA)。我们使用 htpp 请求来发送这些字符串。我们的问题是字符串有时很大,这需要很长时间。还有其他方法吗?

We are developing an iphone app that sends json strings of locations user has been at to a web app (JAVA) that is deployed on google app engine. We use htpp requests to send these strings. Our problem is that the the strings are large sometimes and this takes too long time. Is there any other method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清浅ˋ旧时光 2025-01-03 10:16:37

您可以压缩您的 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();
}

You can compress your JSON. This is the piece of code for GAE:

JSONObject json = new JSONObject(uncompress(Base64.decode(encodedJSONData)));

This is the uncompress method:

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();
}
百变从容 2025-01-03 10:16:37

如果您的系统正在发送位置集合,请尝试不要一次发送所有位置,而是将整个集合分成小块,您估计的大小不会花费太多时间。

另一个想法:如果您将发送作为后台进程进行,则主进程(如用户界面中)不应受到惩罚。

If your system is sending a collection of locations, try not sending them all at a time, but splitting the whole collection in small blocks, with a size that you estimate doesn't take too much time.

Another idea: if you do this sending as a background process, the main process (as in user interface) shouldn't be penalized.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文