0

Is there any tool out there can convert Java's JSON to/from C#?

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I have mislead everyone again! What i was asking is I want to know is there any mapping tool out there can convert "Java generated json object" into C# object, and vice vance.
@Bryan Fok - perhaps you should read this. JSON is data notation - you seem to want a .NET library that can read JSON and generate C# classes from it (or deserialize the JSON into existing C#). Can you please edit your question and clarify exactly what you are looking for?
0

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:

Comments

0

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.

2 Comments

I have mislead everyone again! What i was asking is I want to know is there any mapping tool out there can convert "Java generated json object" into C# object, and vice vance.
Ah, then ignore my suggestion. :-) Btw: you can still edit the question to maybe clarify wording a bit?
0

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.

2 Comments

I have mislead everyone again! What i was asking is I want to know is there any mapping tool out there can convert "Java generated json object" into C# object, and vice vance.
As mentioned by Oded, there is no difference between JSON generated by Java and any other JSON. It is notation used to represent an object. If you need to convert JSON to/from a C# object you should use the DataContractJsonSerializer. If you need to do the conversion on the Java side I would recommend looking at Jackson mentioned by StaxMan

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.