directionDisplay.setDirections() a.lat is not a function
<p>I am setting the directions in map using direction.setDirection method and getting directions form stored json file. When i load directions without <strong>waypoints</strong>, it works fine. But when i load directions with waypoints it gives me error <strong>a.lat is not a function</strong>. Display starting location (A) and one waypoint on map. </p>

<p><a href="https://i.stack.imgur.com/V1VH7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V1VH7.png" alt="enter image description here"></a></p>

<p>code to load directions on map</p>

<pre><code>function route() {
    $.ajax({
        type: 'POST',
        url: '/Home/GetRoute',
        success: function (response) {
            //alert(response);
            var route = JSON.parse(response);
            alert(route.Data);
            //alert(data);

            directionDisplay.setDirections(JSON.parse(route.Data));
        },
        error: function (error) {
            alert('Error: ' + error);
        }

    });
</code></pre>

<p><strong>Update:</strong> i am double parsing it because its an object with attribute Data.
response is an object with property Data which contains json string.</p>

<p>{ "Data": "{"geocoded_waypoints":[{"geocoder_status":"OK","p... so on</p>

<p>So first i parse the obj to get the obj.Data output and then parse obj.Data to get inner json string of obj.Data.</p>

<p>this is how i am saving the route:</p>

<pre><code>function saveRoute()
    {
        var result = directionDisplay.getDirections();

        alert(JSON.stringify(result));
        var url = "/Home/SaveRoute";
        directionDisplay.setDirections(result);
        $.ajax({
            type: 'POST',
            url: url,
            data: JSON.stringify({ jsonRoute: { Data: JSON.stringify(result) } }), //JSON.stringify(result)
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            async: true,
            processData: false,
            cache:false,
            success: function (data) {
                alert("Success");
            },
            error: function (error) {
                alert("Error: "+error.statusText);
            }
        });

    }
</code></pre>

<p>and here is json file data that i am loading:</p>

<pre><code>    {   "Data": "{\"geocoded_waypoints\":[{\"geocoder_status\":\"OK\",\"place_id\"
:\"ChIJ3dTEVV0DGTkRXqaSzKf50y8\",\"types\":[\"sublocality_level_1\",\"sublocal
ity\",\"political\"]},{\"geocoder_status\":\"OK\",\"place_id\":\"ChIJE4xqmkIDG
TkRQGFN4MjBPzU\",\"types\":[\"route\"]},{\"geocoder_status\":\"OK\",\"place_id
\":\"ChIJifnoE2gDGTkRtEVKM-PhYGU\",\"types\":[\"route\"]}],\"routes\":[{\"boun
ds\":{\"south\":31.534670000000002,\"west\":74.29780000000001,\"north\":31.535
54,\"east\":74.29865000000001},\"copyrights\":\"Map data ©2016
Google\",\"legs\":[{\"distance\":{\"text\":\"0.2
km\",\"value\":210},\"duration\":{\"text\":\"1
min\",\"value\":52},\"end_address\":\"Poonch Rd, Lahore, Pakistan\",\"end_loca
tion\":{\"lat\":31.5346676,\"lng\":74.29839379999999},\"start_address\":\"Sama
nabad, Lahore, Pakistan\",\"start_location\":{\"lat\":31.5355392,\"lng\":74.29
846520000001},\"steps\":[{\"distance\":{\"text\":\"19
m\",\"value\":19},\"duration\":{\"text\":\"1 min\",\"value\":4},\"end_location
\":{\"lat\":31.5354648,\"lng\":74.29864729999997},\"polyline\":{\"points\":\"c
hn_EmlndMJ]BE\"},\"start_location\":{\"lat\":31.5355392,\"lng\":74.29846520000
001},\"travel_mode\":\"DRIVING\",\"encoded_lat_lngs\":\"chn_EmlndMJ]BE\",\"pat
h\":[{\"lat\":31.53554,\"lng\":74.29847000000001},{\"lat\":31.535480000000003,
\"lng\":74.29862},{\"lat\":31.535460000000004,\"lng\":74.29865000000001}],\"la
t_lngs\":[{\"lat\":31.53554,\"lng\":74.29847000000001},{\"lat\":31.53548000000
0003,\"lng\":74.29862},{\"lat\":31.535460000000004,\"lng\":74.29865000000001}]
,\"instructions\":\"Head &lt;b&gt;southeast&lt;/b&gt; on &lt;b&gt;Rajput Street&lt;/b&gt;\",\"maneuver
\":\"\",\"start_point\":{\"lat\":31.5355392,\"lng\":74.29846520000001},\"end_p
oint\":{\"lat\":31.5354648,\"lng\":74.29864729999997}},{\"distance\":{\"text\"
:\"21 m\",\"value\":21},\"duration\":{\"text\":\"1 min\",\"value\":9},\"end_lo
cation\":{\"lat\":31.5352878,\"lng\":74.29856440000003},\"maneuver\":\"turn-ri
ght\",\"polyline\":{\"points\":\"sgn_EqmndM@@^N\"},\"start_location\":{\"lat\"
:31.5354648,\"lng\":74.29864729999997},\"travel_mode\":\"DRIVING\",\"encoded_l
at_lngs\":\"sgn_EqmndM@@^N\",\"path\":[{\"lat\":31.535460000000004,\"lng\":74.
29865000000001},{\"lat\":31.53545,\"lng\":74.29864},{\"lat\":31.53529000000000
3,\"lng\":74.29856000000001}],\"lat_lngs\":[{\"lat\":31.535460000000004,\"lng\
":74.29865000000001},{\"lat\":31.53545,\"lng\":74.29864},{\"lat\":31.535290000
000003,\"lng\":74.29856000000001}],\"instructions\":\"Turn &lt;b&gt;right&lt;/b&gt;\",\"st
art_point\":{\"lat\":31.5354648,\"lng\":74.29864729999997},\"end_point\":{\"la
t\":31.5352878,\"lng\":74.29856440000003}},{\"distance\":{\"text\":\"0.1
km\",\"value\":103},\"duration\":{\"text\":\"1 min\",\"value\":25},\"end_locat
ion\":{\"lat\":31.535005,\"lng\":74.29780319999998},\"maneuver\":\"turn-right\
",\"polyline\":{\"points\":\"qfn_E_mndM_@pAHHd@Vh@b@\"},\"start_location\":{\"
lat\":31.5352878,\"lng\":74.29856440000003},\"travel_mode\":\"DRIVING\",\"enco
ded_lat_lngs\":\"qfn_E_mndM_@pAHHd@Vh@b@\",\"path\":[{\"lat\":31.5352900000000
03,\"lng\":74.29856000000001},{\"lat\":31.53545,\"lng\":74.29815},{\"lat\":31.
535400000000003,\"lng\":74.2981},{\"lat\":31.535210000000003,\"lng\":74.297980
00000001},{\"lat\":31.535000000000004,\"lng\":74.29780000000001}],\"lat_lngs\"
:[{\"lat\":31.535290000000003,\"lng\":74.29856000000001},{\"lat\":31.53545,\"l
ng\":74.29815},{\"lat\":31.535400000000003,\"lng\":74.2981},{\"lat\":31.535210
000000003,\"lng\":74.29798000000001},{\"lat\":31.535000000000004,\"lng\":74.29
780000000001}],\"instructions\":\"Turn &lt;b&gt;right&lt;/b&gt;\",\"start_point\":{\"lat\"
:31.5352878,\"lng\":74.29856440000003},\"end_point\":{\"lat\":31.535005,\"lng\
":74.29780319999998},\"Hc\":[{\"path\":[{\"lat\":31.535290000000003,\"lng\":74
.29856000000001},{\"lat\":31.5354257,\"lng\":74.29821700000002}],\"polyline\":
{},\"travel_mode\":\"DRIVING\"},{\"path\":[{\"lat\":31.5354257,\"lng\":74.2982
1700000002},{\"lat\":31.53545,\"lng\":74.29815},{\"lat\":31.535400000000003,\"
lng\":74.2981},{\"lat\":31.535210000000003,\"lng\":74.29798000000001},{\"lat\"
:31.535000000000004,\"lng\":74.29780000000001}],\"polyline\":{},\"travel_mode\
":\"DRIVING\"}]},{\"distance\":{\"text\":\"67
m\",\"value\":67},\"duration\":{\"text\":\"1 min\",\"value\":14},\"end_locatio
n\":{\"lat\":31.5346676,\"lng\":74.29839379999999},\"maneuver\":\"turn-left\",
\"polyline\":{\"points\":\"wdn_EghndM@E|@iB@E\"},\"start_location\":{\"lat\":3
1.535005,\"lng\":74.29780319999998},\"travel_mode\":\"DRIVING\",\"encoded_lat_
lngs\":\"wdn_EghndM@E|@iB@E\",\"path\":[{\"lat\":31.535000000000004,\"lng\":74
.29780000000001},{\"lat\":31.534990000000004,\"lng\":74.29783},{\"lat\":31.534
68,\"lng\":74.29836},{\"lat\":31.534670000000002,\"lng\":74.29839000000001}],\
"lat_lngs\":[{\"lat\":31.535000000000004,\"lng\":74.29780000000001},{\"lat\":3
1.534990000000004,\"lng\":74.29783},{\"lat\":31.53468,\"lng\":74.29836},{\"lat
\":31.534670000000002,\"lng\":74.29839000000001}],\"instructions\":\"Turn &lt;b&gt;l
eft&lt;/b&gt;\",\"start_point\":{\"lat\":31.535005,\"lng\":74.29780319999998},\"end_
point\":{\"lat\":31.5346676,\"lng\":74.29839379999999}}],\"via_waypoint\":[{\"
location\":{\"lat\":31.5354257,\"lng\":74.29821700000002},\"step_index\":2,\"s
tep_interpolation\":0.3536570332799496}],\"via_waypoints\":[{\"lat\":31.535425
7,\"lng\":74.29821700000002}]}],\"overview_polyline\":\"chn_EmlndMNc@`@P_@pAn@
`@h@b@@E~@oB\",\"summary\":\"Rajput Street\",\"warnings\":[],\"waypoint_order\
":[],\"overview_path\":[{\"lat\":31.53554,\"lng\":74.29847000000001},{\"lat\":
31.535460000000004,\"lng\":74.29865000000001},{\"lat\":31.535290000000003,\"ln
g\":74.29856000000001},{\"lat\":31.53545,\"lng\":74.29815},{\"lat\":31.5352100
00000003,\"lng\":74.29798000000001},{\"lat\":31.535000000000004,\"lng\":74.297
80000000001},{\"lat\":31.534990000000004,\"lng\":74.29783},{\"lat\":31.5346700
00000002,\"lng\":74.29839000000001}]}],\"status\":\"OK\",\"request\":{\"origin
\":\"Samanabad, Lahore, Punjab, Pakistan\",\"destination\":{\"lat\":31.5346676
,\"lng\":74.29839379999999},\"travelMode\":\"DRIVING\",\"Xc\":1,\"waypoints\":
[{\"location\":{\"lat\":31.535360412959733,\"lng\":74.29818126631949},\"stopov
er\":false}],\"optimizeWaypoints\":false,\"mg\":17},\"j\":true}" }
</code></pre>