【发布时间】:2016-10-20 14:09:29
【问题描述】:
我检查了 at 的 JSON 字符串响应 https://jsonformatter.curiousconcept.com/ 它说 JSON 字符串是有效的。
以下是我用来将数据序列化为 JSON 字符串的函数:
private string getJSONData()
{
obj_userSession = new UserSession();
DataTable dtRender = null;
DataView dvRender = null;
obj_userSession = new UserSession();
if (obj_userSession.LoginData != null && obj_userSession.EmailsDetails != null)
{
dvRender = new DataView(obj_userSession.EmailsDetails);
dtRender = dvRender.ToTable("EmailsDetails", false, "MessageDate", "SentFrom", "MessageBody", "SentTo", "MLSNumber");
return JsonConvert.SerializeObject(dtRender);
}
return "";
}
这是来自上述函数的 JSON 字符串响应:
[
{
"MessageDate": "2016-04-04T05:42:38.273",
"SentFrom": "Site Team",
"MessageBody": "<html>\r\n<head>\r\n\t<style type=\"text/css\">\r\n\t\t.c0 { font-family:'Arial';font-size:10.5pt; }\r\n\t\t.c1 { margin-left:0pt;margin-top:0pt;margin-right:0pt;margin-bottom:7.5pt; }\r\n\t</style>\r\n</head>\r\n<body class=\"c0\">\r\n<p class=\"c1\">Hi Joe, </p>\r\n<p class=\"c1\">Testing Site</p>\r\n<p class=\"c1\">--James</p>\r\n<p class=\"c1\"></p>\r\n</body>\r\n</html>\r\n",
"SentTo": "James",
"Number": ""
}
]
我们在代码中没有收到任何错误,但结果未显示在浏览器中。并在浏览器的开发人员工具中出现上述错误。
如果我从函数getJSONData 中删除MessageBody 以避免序列化并从MessageBody 的设计页面中删除绑定代码,那么它可以正常工作。
我必须从MessageBody 中逃脱什么角色以及如何做到这一点?
编辑 这是我用来获取数据的 AngularJS 控制器函数:
$scope.browseListing = function (strURL) {
$scope.getURL(strURL);
$http.post($scope.URL)
.then(function (response) {
$scope.Data = response.data;
if ($scope.IsMap)
$scope.LoadMapData();
if ($scope.IsDetails)
$scope.buildReportURL($scope.Data[0].ListingID);
}, function (response) {
$log.info(response);
});
};
这是 html 绑定:
<tr ng-repeat="listing in Data">
<td colspan="6">
<table class="tblListingOuter">
<tr>
<th style="width:20%;">
</th>
<th style="width:80%;">
</th>
</tr>
<tr>
<td><b>Date: </b>{{ listing.MessageDate }}</td>
<td><b>Message: </b></td>
</tr>
<tr>
<td><b>Sent By: </b>{{ listing.SentFrom }}</td>
<td rowspan="3">
<pre contenteditable="true" ng-bind-html="listing.MessageBody | unsafe"></pre>
</td>
</tr>
<tr>
<td><b>Sent To: </b>{{ listing.SentTo }}</td>
</tr>
<tr>
<td><b>MLSNO: </b>{{ listing.MLSNumber }}</td>
</tr>
</table>
</td>
</tr>
【问题讨论】:
-
您的Json无效,请在jsonlint.com查看
-
您是否打算在 JSON 末尾添加分号?
-
是的,如果你删除它通过 lint 测试
-
@HomrZodyssey,那个分号在发布问题时被错误地添加了..
-
你能展示你用来读取 JSON 的代码吗?