When trying to parse the serialized string from an object in json, I keep receiving an error saying it cant be parsed. Popwe class comprises of three decimal properies (peak, offpeak, weekend)
I have a object which comprises of the below classes
public class MinimumsAndParentRates {
public MinimumsAndParentRates() {
PerCall = new ListPopwes();
PerMinute = new ListPopwes();
}
public ListPopwes PerCall { get; set; }
public ListPopwes PerMinute { get; set; }
}
public class ListPopwes {
public ListPopwes() {
MinimumMargin = new Popwe();
MinimumRetention = new Popwe();
MasterRate = new Popwe();
}
public Popwe MinimumMargin { get; set; }
public Popwe MinimumRetention { get; set; }
public Popwe MasterRate { get; set; }
}
I then set a view model property like so
viewmodel.JsonData = JsonConvert.SerializeObject(obj);
When I write out the result I get the below string
{
"PerCall":
{
"MinimumMargin":
{
"Peak":0.00000000,
"OffPeak":0.00000000,
"Weekend":0.00000000
},
"MinimumRetention":
{
"Peak":0.00000000,
"OffPeak":0.00000000,
"Weekend":0.00000000
},
"MasterRate":
{
"Peak":0.00000000,
"OffPeak":0.00000000,
"Weekend":0.00000000
}
},
"PerMinute":
{
"MinimumMargin":
{
"Peak":0.00000000,
"OffPeak":0.00000000,
"Weekend":0.00000000
},
"MinimumRetention":
{
"Peak":0.20000000,
"OffPeak":0.20000000,
"Weekend":0.20000000
},
"MasterRate":
{
"Peak":1.00000000,
"OffPeak":2.00000000,
"Weekend":3.00000000
}
}
}
However when I try to parse this as JSON using jquery I receive the error, I have tried the below.
console.log("@Model.JsonData");
var array = "@Html.Raw(Json.Encode(Model.JsonData))" //Error occurs on this line when using Html.Raw;
var obj = $.parseJSON(array); //Error occurs on this line when not using Html.Raw
console.log(array);
The following are the error messages I get
@Html.Raw - SyntaxError: missing ; before statement
parsing - SyntaxError: JSON.parse: unexpected character