开发者

my C# client app need to deserialize complex JSON sent by Java app

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.re开发者_如何学Gofdata.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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜