Mapping tool for converting Java's JSON to/from C#

狂风中的少年 提交于 2019-12-01 14:36:55

JSON is a data interchange format (JavaScript Object Notation) that is not tied to either Java or .NET or any specific implementation.

Are you looking for a JSON library for .NET? There are links to many libraries for different platforms and languages at the bottom of the linked page.

AFAIK Json is not server-side-language-dependent, since it applies to JavaScript, not strictly to Java or C#. Given this, a Json correctly formatted should correctly work with any parser in any server-side language. If you are searching a C# implementation for Json handling, take a look at these sources:

StaxMan

And to complement with Java-side tools (which are aplenty as well), I suggest having a look at Jackson JSON parser/databinder. For other suggestions there are many many SO questions, such as this one.

In .NET you can use the DataContract and DataMember attributes from the System.Runtime.Serialization to define the variables of the Json object like this

using System.Runtime.Serialization;

[DataContract]
class MyJSONObject
{
    [DataMember(Name="property1")]
    public int Property1
    {
        get;
        set;
    }

    [DataMember(Name = "property2")]
    public int Property2
    {
        get;
        set;
    }
}   

Then, provided you are using .NET 3.5 or later, you can use the DataContractJsonSerializer class from the System.Runtime.Serialization.Json namespace to serialize your object to a JSON string or deserialize a JSON string to your object.

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