Newtonsoft JArray ToString double quotes in ASP.NET MVC razor -
i have created jarray list:
jarray branchesjson = new jarray(); then while iterating using foreach add objects list like:
// add branch json array branchesjson.add(new jobject { {"name", branch.name}, {"lat", branchdetails.lat}, {"long", branchdetails.long} }); this done in razor on view. need output added javascript in same view @ bottom in seperated section.
@section scripts { <script> /* <![cdata[ */ jquery(document).ready(function ($) { 'use strict'; var locations = @branchesjson.tostring(); alert(json.stringify(locations)); }); /* ]]> */ </script> } then using .tostring() method output like:
[ { "name": "brugge", "lat": "51.246701", "long": "3.200326" }, { "name": "destelbergen", "lat": "51.052056", "long": "3.761034" }, { "name": "sint-niklaas", "lat": "51.143114", "long": "4.171444" }, { "name": "terneuzen", "lat": "51.301069", "long": "3.848187" }, { "name": "vlissingen", "lat": "51.472778", "long": "3.592411" } ] this gives errors in error console.
when use replace function .replace(""", "\"") still showes me " instead of ".
you should use html.raw this:
var locations = @html.raw(branchesjson.tostring()); wraps html markup in htmlstring instance interpreted html markup.
Comments
Post a Comment