We are pleased to inform you that we have released an open-source extension for CSHTML5 that adds JSON serialization/deserialization support!

If you are new to the concept of Extensions for CSHTML5, you can read more here.

UPDATE (November 9, 2018): Added Bridge.NET support, added a bunch of stubs, and changed namespace from "CSHTML5.Extensions.Json" to "Newtonsoft.Json"UPDATE (September 12, 2018): Improved support for Long types (Int64)UPDATE (October 13, 2017): Added support for case-insensitive deserialization: if the case-sensitive property is not found, the deserializer looks for the case-insensitive property. Also added JsonArray object with ability to count the number of items.UPDATE (September 13, 2017): Fixed an issue with static properties that interfered with the serialization/deserialization. Furthermore, private properties are no longer serialized by default. To serialize them, add "BindingFlags.NonPublic" to the "GetProperties" call.UPDATE (July 14, 2017): Improved support for numbers and booleans that are surrounded by quotes. Improved support for generic list deserialization.UPDATE (June 20, 2017): Added support for Guid, null, Nullable<>, and ObservableCollection. Improved support for collections and enumerables.UPDATE (June 8, 2017): Fixed issue with deserialization of empty arrays.UPDATE (April 2017): Added support for Enum and DateTime.

How to install/use it?

To install and use it, simply add a new class named "JsonConvert.cs" to your project, and copy/paste the code from the following URL:

MessageBox.Show("Name of the second feature: " + deserializedProduct.Features[1].Name);MessageBox.Show("Name of the third available size: " + deserializedProduct.Sizes[2]);MessageBox.Show("Release date: " + deserializedProduct.ReleaseDate.ToString());

MessageBox.Show("Product name: " + deserializedObject["Name"].Value.ToString());MessageBox.Show("Name of the second feature: " + deserializedObject["Features"][1]["Name"].Value.ToString());MessageBox.Show("Name of the third available size: " + deserializedObject["Sizes"][2].Value.ToString());

Sorry if this is a ridiculous question - I've got limited programming knowledge that I tend to gather just as I need it. I have been using C# to make web service call and deserialize the JSON through JSON.Net, but that's obviously not possible with C#/XAML. The web service I'm working with uses spaces in field names, so with JSON.Net I was able to set the "JsonProperty" in the classes:

UPDATE: The JSON extension has been updated with the following features:- Support for Guid- Support for null and Nullable<>- Support for ObservableCollection- Improved support for collections and enumerables

UPDATE: The JSON extension has been updated today with the following features:- Improved support for numbers and booleans that are surrounded by quotes.- Improved support for generic list deserialization.

UPDATE: The JSON extension has just been updated with the following features:- Fixed an issue with static properties that interfered with the serialization/deserialization.- Private properties are no longer serialized by default. To serialize them, add "BindingFlags.NonPublic" to the "GetProperties" call.

UPDATE: The JSON extension has just been updated with the following features:- Added support for case-insensitive deserialization: if the case-sensitive property is not found, the deserializer looks for the case-insensitive property.- Added JsonArray object with ability to count the number of items.

I'm trying to deserialize an array of custom objects. However, the result is the same object on every place in the array. It somehow puts the last object in the serialized array on all place on the deserialized array.

I'm not doing anything exotic I think. I will test with the given examples if I can reproduce this issue.

stan0611 wrote:I get the following error: A first chance exception of type 'System.InvalidOperationException' occurred in TestCshtml5WCF.dll Additional information: Cannot convert a string to 'System.String[]'.

stan0611 wrote:the result is the same object on every place in the array. It somehow puts the last object in the serialized array on all place on the deserialized array.

Thanks for reporting this issue.

It has now been fixed in CSHTML5 v1.1.2, which will be available before the end of the week.

UPDATE: The JSON extension has just been updated with the following changes:- Added Bridge.NET support- Changed namespace from "CSHTML5.Extensions.Json" to "Newtonsoft.Json"- Added "Required" enum, "NullValueHandling" enum, and JsonProperty stub (not functional)