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:

[   {     &quot;name&quot;: &quot;brugge&quot;,     &quot;lat&quot;: &quot;51.246701&quot;,     &quot;long&quot;: &quot;3.200326&quot;   },   {     &quot;name&quot;: &quot;destelbergen&quot;,     &quot;lat&quot;: &quot;51.052056&quot;,     &quot;long&quot;: &quot;3.761034&quot;   },   {     &quot;name&quot;: &quot;sint-niklaas&quot;,     &quot;lat&quot;: &quot;51.143114&quot;,     &quot;long&quot;: &quot;4.171444&quot;   },   {     &quot;name&quot;: &quot;terneuzen&quot;,     &quot;lat&quot;: &quot;51.301069&quot;,     &quot;long&quot;: &quot;3.848187&quot;   },   {     &quot;name&quot;: &quot;vlissingen&quot;,     &quot;lat&quot;: &quot;51.472778&quot;,     &quot;long&quot;: &quot;3.592411&quot;   } ] 

this gives errors in error console.

when use replace function .replace("&quot;", "\"") still showes me &quot; instead of ".

you should use html.raw this:

var locations = @html.raw(branchesjson.tostring()); 

here there documentation:

wraps html markup in htmlstring instance interpreted html markup.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -