我在Breeze 1.1.2的breeze.debug.js第12565行收到了无效字符错误。该行是:
var metadata = JSON.parse(data);
我已经研究过这条错误消息,而且我看到的最佳建议是使用未转义的单引号或双引号或无效字符。但是,我无法在回复中找到。
我正在使用BreezeJS发出请求并处理响应。响应由Breeze.WebApi.EFContextProvider.Metadata()生成。我在Windows 8.1上使用IE11。生成响应的服务器是IIS Express 8.我使用Fiddler捕获了请求和响应。
有人能看出回复有什么问题吗?
请求:
GET http://localhost/RisingTide.API/breeze/scheduledpayments/Metadata HTTP/1.1
X-Requested-With: XMLHttpRequest
Accept: application/json, text/javascript, */*; q=0.01
Referer: http://localhost/RisingTide.Web/#/scheduledpayments
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko
Host: localhost
DNT: 1
Connection: Keep-Alive
响应:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 862
Content-Type: application/json
Expires: -1
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sun, 15 Sep 2013 03:37:14 GMT
{"schema":{"namespace":"RisingTide.API.Models","alias":"Self","d4p1:UseStrongSpatialTypes":"false","xmlns:d4p1":"http://schemas.microsoft.com/ado/2009/02/edm/annotation","xmlns":"http://schemas.microsoft.com/ado/2009/11/edm","cSpaceOSpaceMapping":"[[\"RisingTide.API.Models.ScheduledPayment\",\"RisingTide.API.Models.ScheduledPayment\"]]","entityType":{"name":"ScheduledPayment","key":{"propertyRef":{"name":"Id"}},"property":[{"name":"Id","type":"Edm.Int32","nullable":"false","d4p1:StoreGeneratedPattern":"Identity"},{"name":"Description","type":"Edm.String","fixedLength":"false","maxLength":"4000","unicode":"true","nullable":"true"},{"name":"Amount","type":"Edm.Decimal","precision":"18","scale":"2","nullable":"false"}]},"entityContainer":{"name":"ScheduledPaymentsDbContext","entitySet":{"name":"ScheduledPayments","entityType":"Self.ScheduledPayment"}}}}
答案 0 :(得分:0)
看起来JSON.parse正在\"
上绊倒。看起来JSON似乎不支持。
"[[\"RisingTide.API.Models.ScheduledPayment\",\"RisingTide.API.Models.ScheduledPayment\"]]"
引号必须双重反映,如下所示:
"[[\\"RisingTide.API.Models.ScheduledPayment\\",\\"RisingTide.API.Models.ScheduledPayment\\"]]"
必须是“”被视为“”的内部,但是\“被视为”“内部”。
有趣。在我尝试之前我不知道。 : - )
更新:与CDT会话的屏幕截图应该有助于解释更好的内容:
您可以看到,当您使用单个反斜杠时,JSON将削减"""
,这不是有效的JSON字符串。但是对于\,JSON将解析一个\和3“s,这是有效的。
答案 1 :(得分:0)
Breeze v1.1.2已经很老了。我们在早期版本中修复了许多这样的错误。最新的当前稳定版本是1.4.2