I am encountering a JavaScript error while attempting to parse JSON data obtained from my controller:
Uncaught SyntaxError: Unexpected token & in JSON at position 1 at JSON.parse () at stores:76
This is the code I use to serialize my list of elements (so I can send it as a string to the frontend and then parse it with JSON.parse()
)
FeatureCollection mapFeatureCollection = new FeatureCollection(mapFeatures); // this is my object
// Use the ToJson method provided by FeatureCollection instances to convert them into JSON strings before sending them to the frontend
string nearbyStoresAsGeoJSON = JsonConvert.SerializeObject(mapFeatureCollection, Formatting.Indented);
// pass the json to view to mark them
ViewBag.nearbyStores = nearbyStoresAsGeoJSON;
return View("Stores");
I suspect the issue arises when I receive the JSON in the frontend and log it to the console, here is what I observe:
{
 ... (the JSON content)...}