8

The following JSON is not deserializing. It's obviously because the DECIMALS in the saves JSON. How do I fix this?

This initial JSON comes from the server and 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' 
    }

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' 
    }

This code throws the Error:

    try
    {
        if (!String.IsNullOrEmpty(this.JSON))
        {
            serializer = new JavaScriptSerializer();
            dialog = serializer.Deserialize<ProjectDecorator>(this.JSON);
        }
    }
    catch (Exception ex)
    {
        // The message shows here
    }

The Error thrown looks like:

{"Invalid JSON primitive: ."}
Prisoner ZERO
  • 13,848
  • 21
  • 92
  • 137

2 Answers2

11

"ClientKey": , has no value

http://www.jsonlint.com/

James Kyburz
  • 13,775
  • 1
  • 32
  • 33
11

Not only does ClientKey have no value, but you're risking JSON validness by not putting keys and values inside double quotations marks ("").

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.

darioo
  • 46,442
  • 10
  • 75
  • 103