【问题标题】:Serializing DirectionsResult to JSON to send to my webservice not working fine将 DirectionsResult 序列化为 JSON 以发送到我的网络服务无法正常工作
【发布时间】:2016-03-18 06:57:27
【问题描述】:

我正在使用 Google 地图 Javascript API,当用户更改地图上的路线/路线时(可拖动设置为 true),我想将新路线/路线结果发送到我的网络服务后端。我面临的问题是,当我使用 JSON.stringify 序列化 DirectionsResults 时,我似乎没有将完整的对象列表正确转换为字符串。

   directionsDisplay.addListener('directions_changed', function () {
            sendToBackendService(directionsDisplay.getDirections());
        });

    function sendToBackendService(result) {
        var jsonToSend = JSON.stringify(result);

        $.ajax({
            type: 'POST',
            url: './api/DirectionsUserModified',
            data: jsonToSend,
            error: processCallbackError,
            success: function (apiJson) {
                alert("post of new directions success");
            }

        });

    }

【问题讨论】:

    标签: javascript json google-maps google-maps-api-3


    【解决方案1】:

    问题总是与 JavaScript 代码执行的本地环境有关。因此,您正在使用的网络浏览器版本。

    可能由于达到了大小限制,对象无法正确序列化。导航器在 json 序列化过程中使用本地存储作为缓冲区。如果达到限制,则简单地截断字符串或​​抛出错误。

    你可以看看to this other post,也许会有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-21
      • 2016-05-24
      • 1970-01-01
      • 1970-01-01
      • 2012-04-03
      • 2011-06-01
      • 1970-01-01
      • 2014-03-22
      相关资源
      最近更新 更多