1

Its asp.net mvc paradigm. I have a Prices property on model that is an IList of type VMPrice. In view I do something like

<%var serializer = System.Web.Script.Serialization.JavaScriptSerializer();%>
<script type="text/javascript">
  var prices = '<%:serializer.Serialize(Model.Prices)%>';
  alert(prices);
  prices = $.parseJSON(prices);  // This line throws exception Invalid Json object
</script>

The alert call on fourth line shows following string

[{&quot;SKUID&quot;:3,&quot;ExFactoryPrice&quot;:765.00},{&quot;SKUID&quot;:5,&quot;ExFactoryPrice&quot;:39.91}]

What's the problem here and how to get around this?

2 Answers 2

1

try using "<%=%>" instead of <%: %> so that it does not html encode it

also see this SO answer c# to json not rendering properly in view

Sign up to request clarification or add additional context in comments.

Comments

0

You need to unescape the string before parsing it.

[{&quot;SKUID&quot;:3,&quot;ExFactoryPrice&quot;:765.00},{&quot;SKUID&quot;:5,&quot;ExFactoryPrice&quot;:39.91}]


Should be:

[{"SKUID":3,"ExFactoryPrice":765.00},{"SKUID":5,"ExFactoryPrice":39.91}]

The simple thing in this case would be to replace &quote; with "

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.