parse error

Feb 22, 2011 at 9:49 PM
Edited Feb 22, 2011 at 9:54 PM

 

I am trying to consume an ODATA feed that is throwing an error when the json data that is returned is parsed - IE8 gives me Error Occurred Invalid Character, IE7 Error occurred Unable to get value of the property 'parse' : object is null or undefined, Firefox Error occurred JSON.parse.

You will notice from the json below the ODATA feed contains some guids - I was able to get jsonlint to validate it as long as I deleted the \ that is escaping the single quote that comes before and after the guid value in the __metadata section.

{
"d" : {
"__metadata": {
"uri": "http://localhost/imap/tool/IMapDataService.svc/InterventionSets(guid\'a0fec1a5-373b-43cc-802a-037151e416ef\')", "type": "IMapModel.InterventionSet"
}, "GUID": "a0fec1a5-373b-43cc-802a-037151e416ef", "Name": "Standard Precautions", "Description": "Establish a reliable approach to ensure that standard precautions are used to prevent transmission of infections."
}
}

here is the call I am making

OData.read("imapdataservice.svc/InterventionSets(guid'a0fec1a5-373b-43cc-802a-037151e416ef')?$select=Name,Description,GUID&$expand=Aims,Domains",
   function (data, request) {
      alert("success");
     },
   function (err) {
      alert("Error occurred " + err.message);
     }
  );

 

I was also having trouble calling the service directly with jquery and jsonGet - I was getting a similar parsing error.

thanks
Michael

 

Feb 24, 2011 at 6:35 PM
Edited Feb 24, 2011 at 9:09 PM

Hello Michael

Seems that your service is using an older version of WCF Data Services (formerly ADO.NET Data Services) that escapes single quotes when serializing to JSON.  This issue was resolved in both .NET 4.0  and an update for .NET 3.5 sp1.

You can get the .NET 3.5 sp1 update at:

http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=21f20103-551e-4501-89b3-e53fcac5cffd 

And .NET 4.0 at:

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9cfb2d51-5ff4-4491-b0e5-b386f32c0992&displaylang=en

Regards,

Alex Trigo.

Feb 25, 2011 at 1:14 PM

Thanks Alex - but I am using the .NET 3.5 SP1 updated dll

here is the reference from the project : C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.Services.dll

and the dll  is File Version : 3.5.30729.5004

And the service specifies maxprotocolversion as v2:

  config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
Is there anything else I can check to confirm that I am running the updated dataservice code?
thanks
Michael
Feb 25, 2011 at 8:59 PM

Hi Michael,

I see, the version that you mention is that of the dll's that come with Win7 and Win2k8 R2 and the link I originally gave you was for XP, Vista, and Win 2k8.  Here is the link to the update for Win7 and Win2k8 R2 .NET 3.5 SP1

http://www.microsoft.com/downloads/details.aspx?familyid=3e102d74-37bf-4c1e-9da6-5175644fe22d

In the knowledge base article associated with this download, you will notice that the version of the update is 3.5.30729.5022

Regards,

Alex Trigo.

Feb 28, 2011 at 2:36 PM

Alex,

thanks for the new patch - it works correctly now - the single quotes in the json are no longer getting encoded and the json parse error is gone.

Thanks again
Michael