2011-04-07 15 views
8

El siguiente JSON no está deserializando. Obviamente, es porque los DECIMALES en el salva JSON. ¿Cómo puedo solucionar esto?¿Por qué este JSON vuelve como "primitiva JSON inválida"?

Este JSON inicial viene desde el servidor y es válido:

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

Esta subsiguiente JSON enviado al servidor falla:
Una vez que el usuario edita el formulario, los datos es cliente serializado -side y enviado BACK ... donde (luego) falla al intentar deserializar el 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' 
    } 

Este código produce el error:

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

El error miradas lanzadas como:

{"Invalid JSON primitive: ."} 

Respuesta

11

Esto no sólo ClientKey no tienen valor, pero está arriesgando JSON validness al no poner claves y valores dentro de las comillas dobles ("").

Sus claves están bien, pero los valores string deben estar entre comillas dobles. Eche un vistazo al sitio web JSON para ver lo que está permitido y lo que no.