为什么此JSON返回“无效的JSON原语"? [英] Why is this JSON returning as "Invalid JSON primitive"?
问题描述
以下JSON未反序列化.显然是因为保存JSON中的DECIMALS.我该如何解决?
The following JSON is not deserializing. It's obviously because the DECIMALS in the saves JSON. How do I fix this?
此初始JSON来自服务器且有效:
{
"AppropriationAmount": 25000000,
"AppropriationHours": 56300,
"ArrThreshold": 11,
"ClientKey": 24,
"Description": 'Find and incarcerate the escaped prisoner',
"DirectHours": 50000,
"EndDate": '3/31/2011',
"EngineeringHours": 4000,
"IndirectHours": 2000,
"Key": 1589,
"Number": '0',
"OtherHours": 300,
"ProductivityCurveType": 'BurnedEarned',
"ProjectManager": 'Doctor Who',
"ProjectName": 'Prisoner ZERO',
"StartDate": '5/1/2010'
}
此后续JSON发送到服务器失败:
一旦用户编辑了表单,数据就会在客户端进行序列化并发送回去...在尝试反序列化JSON时失败(然后).
This subsequent JSON sent to the server FAILS:
Once the user edits the form, the data is serialized client-side and sent BACK...where it (then) fails upon attempting to de-serialize the JSON.
{
"AppropriationAmount": 56300.00,
"AppropriationHours": 25000000.00,
"ArrThreshold": 11.00,
"ClientKey": ,
"Description": 'Find and incarcerate the escaped prisoner',
"DirectHours": 50000.00,
"EndDate": '3/31/2011',
"EngineeringHours": 4000.00,
"IndirectHours": 2000.00,
"Key": 1589,
"Number": '0',
"OtherHours": 300.00,
"ProductivityCurveType": 'BurnedEarned',
"ProjectManager": 'Doctor Who',
"ProjectName": 'Prisoner ZERO',
"StartDate": '5/1/2010'
}
此代码引发错误:
try
{
if (!String.IsNullOrEmpty(this.JSON))
{
serializer = new JavaScriptSerializer();
dialog = serializer.Deserialize<ProjectDecorator>(this.JSON);
}
}
catch (Exception ex)
{
// The message shows here
}
引发的错误如下:
{"Invalid JSON primitive: ."}
推荐答案
ClientKey
不仅没有值,而且您还冒着冒JSON有效性的危险,因为没有将键和值放在双引号(""
)内.
Not only does ClientKey
have no value, but you're risking JSON validness by not putting keys and values inside double quotations marks (""
).
您的键确定,但是string
值必须用双引号引起来.查看 JSON 网站,查看允许和禁止的内容.
Your keys are OK, but string
values must be surrounded by double quotes. Take a look at JSON website to see what's allowed and what's not.
这篇关于为什么此JSON返回“无效的JSON原语"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!