RouteResult.toJSON() returns empty object in arcgis 4.9

233
3
12-08-2018 02:56 PM
juanDavid
New Contributor II

As the title says, so when using RouteResult.fromJSON() it returns and objects with properties set in null.

Here is a sample

RouteResult.toJSON() sample  The problem is in Line 113 and 115. Please read them.

Am I doing something wrong?

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Juan,

   Your code pen worked fine for me. I clicked two point in the extent that comes up when the app loads and logged in with my credentials and it produced a route without any issue.

0 Kudos
juanDavid
New Contributor II

I have no problem with the route being solved. The real problem is in lines 113 and 115 when getting a RouteResult object because I need to convert it to JSON using toJSON() method but it doesn't work, it returns an empty object (Line 113) and then when I try to convert it again to a normal RouteResult object (Line 115) it returns a RouteResult object but with null properties (useless). 

Click two points in map then watch the browser console.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Juan,

   The route result is NOT json it is a RouteResult object

RouteResult | API Reference | ArcGIS API for JavaScript 4.9 

So your code would need to look something like this, after requiring the dojo/json module

      function showRoute(data) {
        var routeResult = data.routeResults[0].route;
        var routeResultJSON = JSON.stringify(routeResult);
        console.log(routeResultJSON);

        console.log(JSON.parse(routeResultJSON));

        routeResult.symbol = routeSymbol;
        routeLayer.add(routeResult);
      }