I'm trying to convert a dictionery into a json object, so that I can work with it in my front end.
sortFields = <%= SchrodersHtmlHelper.ToJson(ViewData["SortInfo"])%>开发者_JAVA技巧;
However, I keep on getting "Expected expression" for this all the time and I'm clueless why. Could anyone explain to me what I'm doing wrong?
Edit: The conversion works fine, but I still get this issue in the front end, causing the browser to complain about it.
UPDATE
The JSON is valid according to http://jsonlint.com/, and the issue is reported as resolved by the OP
{
"Name": "Ascending",
"ClassDesignation": "Ascending",
"ShareType": "Ascending",
"Curr": "Ascending",
"DateFirstPriced": "Descending",
"Identifier": "Ascending",
"OneWeakPerf": "Descending",
"OneMonthPerf": "Descending",
"ThreeMonthPerf": "Descending",
"SixMonthPerf": "Descending",
"YTDPerf": "Descending",
"OneYearPerf": "Descending",
"ThreeYearPerf": "Descending",
"FourYearPerf": "Descending",
"FiveYearPerf": "Descending",
"TenYearPerf": "Descending",
"SinceLaunchPerf": "Descending",
"OneYearAnnualisedPerf": "Descending",
"ThreeYearAnnualisedPerf": "Descending",
"FiveYearAnnualisedPerf": "Descending",
"TenYearAnnualisedPerf": "Descending",
"SinceLaunchAnnualisedPerf": "Descending"
}
It means that the JSON in the output isn't well-formed, either because the original is malformed or because it's not being output correctly (or at all, per Pointy's comment). See this answer for a list of common errors. Since you're using Javascript itself, not JSON, some of them won't apply to you, but some will. My guess is a dangling comma; we need to see the JSON to know.
You can validate JSON with this validator, and learn more of the required syntax on the JSON site.
精彩评论