jQueryで各ブラウザのネイティブJSONパーサーを利用するようにする方法。1.3.3で実装される予定。
-
-
Play20 で lift-json を使うモジュール
PlayのJSONより LiftのJSON使ったほうが扱いやすそう。
-
rgrz:What makes a good JSON Editor
I’m seeking for a json editor. After trying every result in the first four pages of google search result, the one named JSON Editor Online looks the best.
Why do I make the choice? What makes a good JSON Editor。
Besides the clean design and style, this one also has some attracting features.
Add node or delete existing one by one click
Duplicate button makes array construction easy
You can drag the node
But still there could be some improvements
Import json from URL
Indicate the error position. JSONLint does a good job on it.
Another special editor is the JSON editor with schema
-
she thinks im kidding, but im not
-
モバイル機器でbookmarkletを利用しサイト構造をjson化。それをクラウドに保存し、デスクトップで快適に調査。
-
フィードをjson化。あれ?
-
JSON API <-> NSObject in one line. Powered by RubyMotion and BubbleWrap.
RemoteModel is designed for JSON APIs which return structures with “nice” properties, in a similar way to ActiveResource did.
-
json - growing pains intro
http://www.youtube.com/watch?v=TRMMjW4ulvY -
Improving on Json.NET Defaults Part 1
Recently while using with the very good Newtonsoft Json.Net library for JSON (Javascript Object Notation) serialization, I found myself wishing the library had different defaults from those provided out of the box.
In this post, I’ll cover what I think is a very common case, and in a follow up cover more advance scenarios like better security settings by default.
To Case or not to CaseWhile .Net prescribes PascalCasing for the Public Interface, i.e. public methods, properties, etc. Many Web Api’s tend to use camelCasing.
So in a typical class in .NET:
“User.FirstName” turns into “user.firstName” in JSON using camel casing.
However this is not the default in Json.NET.
But not to worry, a reasonable solution appeared after digging thru some of the documentation and code.
Json.Net defines an IContractResolver interface as a way to provide a JsonContract. A JsonContract in turn holds the mappings for how an object will be formatted into Json, including the property mappings and how they will be named.
Note: By default Json.NET uses DefaultContractResolver (a class included in the library) as the default IContractResolver. The DefaultContractResolver class in addition to providing the JsonContract, also internally assumes the responsibility of building up the contract (mappings). It is here where we can override the property naming to our desired case.
Armed with this information, we are ready to implement our very own class to configure how Json.Net serializes our properties.
https://gist.github.com/2760442 Breaking down the CodeWe don’t want to duplicate all of James Newton’s (Json.NET author) hard work, therefore we’ll simply inherit from DefaultContractResolver. This class conveniently already has a virtual method called “ResolvePropertyName”. We’ll add a Boolean property named “UseCamelCase” to our class. This is how we’ll toggle the casing.
Since Booleans default to false we maintain the normal behavior and avoid developer surprise when using our code.
In the ResolvePropertyName method we’ll check “UserCamelCase”, if it’s set to “True” we then delegate to a function called “ToCamelCase” for lower casing the first character. The complete implementation is list above.
Using the New Code https://gist.github.com/2760197Now that we have our class we need to part of the settings Json.Net uses when it goes to serialize our objects.
The IContractResolver is a property on the JsonSerializerSettings class. Though you can also set the IContractResolver on the JsonSerializer itself. Presto chango you now can change how Json.NET serializes properties on the fly.
DefaultContractResolver vs CamelCasingPropertyContractResolverJson.NET already includes another IContractResolver appropriately name CamelCasePropertyNamesContractResolver which as the name implies, maps properties to be written as Camel Casing regardless of the originating case.
There are times when a balance needs to be struck between being purely object oriented and being practical. In this case I found it a bit strange that switching the serialization to camel casing required a whole different class instead of a setting.
I believe in this case a more ideal default would be to have a simple Boolean property on the DefaultContractResoler that switches the casing.
In the next post, we’ll continue building on this code to make for more sensible defaults, including making smarter defaults for ensuring better security while working with Json.
- Enjoy
Eddy
All of the code and sample project can be found on MvcJson.Net.
Related Links