JSON.stringify replaces symbol type

202
1
01-25-2019 05:00 PM
DanielWebb
New Contributor III

I’m using Esri JavaScript 4.10.

I have a javascript object with graphics.  When I use JSON.stringify the output is weird.  On all graphics the symbol ‘type’ is changed; ‘simple-marker’ to ‘esriSMS’, ‘simple-fill’ to ‘esriSFS’, etc.

When I use JSON.parse, those values are not returned to the original.  This is causing errors when I try to import it back into the map because ‘new Graphic’ is looking for ‘simple-marker’ while ‘esriSMS’ throws an error.

Does anyone know why JSON.stringify replaces those values?  Or does anyone have a better way of stringify-ing an object?

Thanks!

Tags (1)
0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Esteemed Contributor

Daniel,

  The Graphics class has a toJSON method that you should be using.

https://developers.arcgis.com/javascript/latest/api-reference/esri-Graphic.html#toJSON 

0 Kudos