How would an upgrade from verbose JSON to JSON light affect someone who only looks at the data, and not the metadata?

我只是一个虾纸丫 提交于 2019-12-06 09:20:45

问题


Can anyone explain to me concisely in plain English with a few bullet points what the main differences are between verbose JSON and JSON light for WCF Data Services? I found a document called "JSON light at a glance" by Microsoft, but it's 23 pages long! I don't care about metadata; I only care about the data. I know that JSON light drops the "d" wrapper. Anything else? Are the data types (dates, booleans, etc) sent in the same format?

EDIT: I realize that now Microsoft is now calling JSON light simply "JSON", and JSON verbose is the old, deprecated standard. I am calling the new standard "JSON light" for clarity.


回答1:


"I don't care about metadata; I only care about the data"

That's actually a great tagline for JSON Light as a whole :)

The core principle of JSON light is that servers can cut down on unnecessary metadata in the payload. When a client does need a certain bit of metadata (for example, the URL it should use to edit the entity), the client can generate that URI itself based on common OData URI conventions.

A client can control how much metadata the server should include in the payload by requesting one of the three different metadata levels:

  • "application/json;odata=fullmetadata" for clients who need to use metadata and don't have a way to compute it themselves
  • "application/json;odata=minimalmetadata" for clients who use metadata but are fine computing it themselves
  • "application/json;odata=nometadata" for clients who don't care about any metadata whatsoever

If you're writing a client that really doesn't care about any metadata at all (where metadata includes edit links, entity types, property types, stream information, navigation properties, etc.), then you can request "application/json;odata=nometadata" and you'll just get back a bag of properties.

Even if you don't care about metadata, there are lots of little differences between JSON Verbose and JSON Light. I would strongly recommend relying on a library for this if you're in a language where one is available (for example, in .NET there's the WCF Data Services Client and in Javascript there's datajs or jaydata). Here's a list of a couple differences off the top of my head:

  • In OData v2, DateTimes could be represented using the ticks-based format (e.g., "lastUpdated": "\/Date(1240718400000)\/"), but in v3 JSON only ISO 8601 is supported (e.g., "1992-01-01T00:00:00")
  • There is no "d" wrapper on results payloads anymore.
  • Instead of a "results" wrapper for collection results, there is now a "value" wrapper
  • Instead of "__count" for inline count, JSON Light uses "odata.count"

As an example, take a look at the differences in the payload produced by this query:

http://services.odata.org/v3/OData/OData.svc/Products?$inlinecount=allpages&$top=2&$format=application/json;odata=verbose

Versus this:

http://services.odata.org/v3/OData/OData.svc/Products?$inlinecount=allpages&$top=2&$format=application/json;odata=nometadata



来源:https://stackoverflow.com/questions/17238497/how-would-an-upgrade-from-verbose-json-to-json-light-affect-someone-who-only-loo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!