tags:

views:

51

answers:

2

Hi all

If my C# client app need to deserialize complex JSON from Java server app, what is the best option I have?

Here are two conditions need to consider: 1) speed is the most important 2) Json format could include information about the Java data type, C# client app. need to recognize it and convert it to C# corespondent type. for exmaple,

...,"Variable1" : [ "java.math.BigDecimal", 0E-8 ],
  "Variable2" : [ "com.xmlasia.x5.refdata.instrument.model.MarginGroup"],...

IMO because of point 2, the only way is to build my own deserializer, am I right?

Regard to point 1, if I use Json.net to deserialize the Json, and then convert to arraylist, with it have significant impact on the speed? Is there an other better way?

The disadvantage of the arraylist approach is that the extractJson method get really messy, and I think arraylist is slow.

+1  A: 

I think that the easiest would be to build some bridge that will translate this JSON to something more interoperable.

Darin Dimitrov
+1  A: 

It is unlikely that “speed is the most important”, otherwise the data would need to be send in a binary format. However all the main json parsers are also fast, so this is unlikely to be an issue.

If a parser just ignored the java data type and map fields based on names to the fields in your .net objects you may be ok. Otherwise you need a json parser that will give you back dictionary of the fields so you can process them yourself. There should be no need to write you own string processing code to decode the json, that is a solved problem.

There are lots of json libs for .net, as it is a long time since I looked at them, I can’t recommend the best one for you use.

Ian Ringrose
http://stackoverflow.com/questions/391157/is-there-any-off-the-shelf-json-serialization-helper-class-in-net-bcl may help in using a json lib
Ian Ringrose
we don't have a choose at the format of transport. our duty is to build the client. but thanks for your comment.
Bryan Fok
one more thing, by binary do you mean transfer in byte[]? and then deserialize back to JSON at the node? will it be cost even more to deserialize, and serialize the byte[]? Again assuming client is C#, other end is Java.
Bryan Fok