English 中文(简体)
JSON and Microformats
原标题:

I m looking for opinions on whether microformats should be used to name JSON elements. For instance, there is a microformat for physical addresses, that looks like this:

<div class="adr">
    <div class="street-address">665 3rd St.</div>
    <div class="extended-address">Suite 207</div>
    <span class="locality">San Francisco</span>,
    <span class="region">CA</span>
    <span class="postal-code">94107</span>
    <div class="country-name">U.S.A.</div>
</div>

There is a document available on using JSON and Microformats. The information above could be represented as JSON data like this:

"adr": {
    "street-address":"665 3rd St.",
    "extended-address":"Suite 207",
    "locality":"San Fransicso",
    "region":"CA",
    "postal-code":"94107",
    "country-name":"U.S.A."
},

The issue I have with this is that I d like my JSON data to be as lightweight as possible, but still human readable. While still supporting international addresses, I would prefer something like this:

"address": {
    "street":"665 3rd St.",
    "extended":"Suite 207",
    "locality":"San Fransicso",
    "region":"CA",
    "code":"94107",
    "country":"U.S.A."
},

If I m designing a new JSON API right now, does it make sense to use microformats from the start? Or should I not really worry about it? Is there some other standard that is more specific to JSON that I should look at?

最佳回答

This comes down to a matter of personal choice for a simple reason. The difference using your sample data is approx. 192 bits of data. At this point your process/transfer difference is negligible.

If it s an internal API then your suggested method is more than adequate. It easily identifies each section tersely while still being descriptive. However, if the API is something that you plan on opening up to the public, I would suggest the staying with the micro-format.

问题回答

暂无回答




相关问题
The Fastest DataStructure to Filter with in C#

Currently we are filtering and sorting data with a datatable. /// <summary> /// Filters the data table and returns a new data table with only the filtered rows. /// </summary>...

Efficient queue in Haskell

How can I efficiently implement a list data structure where I can have 2 views to the head and end of the list, that always point to a head a tail of a list without expensive calls to reverse. i.e: ...

Java large datastructure for storing a matrix

I need to store a 2d matrix containing zip codes and the distance in km between each one of them. My client has an application that calculates the distances which are then stored in an Excel file. ...

Holding onto items after a postback

I have an ASP.NET web application and I want to be able to take items from a master list and store them temporarliy into one of four other lists. The other lists need to survive post backs so that ...

negative number in the stack

I am a new student in the compilers world ^_^ and I want to know is legal represent negative number in the stack. For example: infix: 1-5=-4 postfix: 15- The statements are: push(1) push(5) x=...

What type of struct/container would you use in this instance?

I am trying to figure out what type of structure or container I should use for a quick project. I need to have an unknown number of sets that will be entered from the GUI (each one will have a name, ...

热门标签