简体   繁体   中英

Reading Json output from Odata services

I am trying to read the output from odata services in json format. but i am getting the error message as

"The response payload is a not a valid response payload. Please make sure that the top level element is a valid Atom or JSON element or belongs to ' http://schemas.microsoft.com/ado/2007/08/dataservices ' namespace".

NorthwindEntities dc = new NorthwindEntities(new Uri("http://services.odata.org/V3/Northwind/Northwind.svc/"),DataServiceProtocolVersion.V3);
        dc.Format.UseJson(new EdmModel());
        DataServiceQuery<Product> query = (DataServiceQuery<Product>)from o in dc.Products
            where o.UnitPrice > 0
            select o; query.execute();


{"odata.metadata":"http://services.odata.org/V3/Northwind/Northwind.svc/$metadata#Products","value":[{"ProductID":24,"ProductName":"Guaran\u00e1 Fant\u00e1stica","SupplierID":10,"CategoryID":1,"QuantityPerUnit":"12 - 355 ml cans","UnitPrice":"4.5000","UnitsInStock":20,"UnitsOnOrder":0,"ReorderLevel":0,"Discontinued":true},{"ProductID":33,"ProductName":"Geitost","SupplierID":15,"CategoryID":4,"QuantityPerUnit":"500 g","UnitPrice":"2.5000","UnitsInStock":112,"UnitsOnOrder":0,"ReorderLevel":20,"Discontinued":false}]}

You JSON string is not valid as it has a property name with a '.' in it. odata.metadata cannot be resolved.

If you changed that to odata_metadata, or possible went with the solution provided here: enter link description here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM