asp.net – 为什么这个JSON返回“无效的JSON原语”?

以下 JSON未反序列化.这显然是因为DECIMALS在保存JSON中.我该如何解决

这个初始JSON来自服务器和IS VALID:

{
    "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发送到服务器FAILS:
一旦用户编辑了表单,数据就会被客户端序列化并发送回来……然后在尝试反序列化JSON时失败.

{
    "AppropriationAmount": 56300.00,"AppropriationHours": 25000000.00,"ArrThreshold": 11.00,"ClientKey":,"DirectHours": 50000.00,"EngineeringHours": 4000.00,"IndirectHours": 2000.00,"OtherHours": 300.00,"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有效性的风险.

您的密钥没问题,但字符串值必须用双引号括起来.看看JSON网站,看看哪些是允许的,哪些不是.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....