最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Handling messages with Java and JavaScript: JSON or XML? - Stack Overflow

programmeradmin9浏览0评论

I'm currently working on a project which needs some server-client munication. We're planning to use Websockets and a Java server (Jetty) on the server side. So, messages sent must be interpreted with Java from the server and with JavaScript from the client.

Now we're thinking about a protocol and which structure the messages should have. We already have a reference implementation which uses XML messages. But since JSON is designed to be used with JavaScript we're also thinking about the possibility to use JSON-Strings.

Messages will contain data which consists of XML strings and some meta information which is needed to process this data (i.e. store it in a database, redirect is to other clients...). It would be important if the processing of the messages (parsing and creating) would be easy and fast on both server and client side since the application should feature real time speed.

Since we have not the time to test both of the technologies I would be happy about some suggestions based on personal experience or on technical aspects. Is one of the technics more usable than the other or are there any drawbacks in one of them?

Thanks in advance.

I'm currently working on a project which needs some server-client munication. We're planning to use Websockets and a Java server (Jetty) on the server side. So, messages sent must be interpreted with Java from the server and with JavaScript from the client.

Now we're thinking about a protocol and which structure the messages should have. We already have a reference implementation which uses XML messages. But since JSON is designed to be used with JavaScript we're also thinking about the possibility to use JSON-Strings.

Messages will contain data which consists of XML strings and some meta information which is needed to process this data (i.e. store it in a database, redirect is to other clients...). It would be important if the processing of the messages (parsing and creating) would be easy and fast on both server and client side since the application should feature real time speed.

Since we have not the time to test both of the technologies I would be happy about some suggestions based on personal experience or on technical aspects. Is one of the technics more usable than the other or are there any drawbacks in one of them?

Thanks in advance.

Share Improve this question asked Dec 11, 2011 at 13:07 j0kerj0ker 4,1394 gold badges45 silver badges65 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 10

JSON is infinitely easier to work with, in my opinion. It is far easier to access something like data.foo.bar.name than trying to work your way to the corresponding node in XML.

XML is okay for data files, albeit still iffy, but for client-server munication I highly remend JSON.

You are opening a can of worms (again, not the first time).

have a look at this JSON vs XML. also a quick serach on stackoverflow will also be good.

this question might be duplicated across. Like this Stackoverflow XML vs JSON.

In the end answers stays the same. It depends on you. I though agree with many ments there that sometime, XML is overkill (and sometime not).

I agree with Kolink,

The reason, it is better to use JSON because the XML has a big Header, which means each transfer has a big overhead.

For iOS or Android, you have to use JSON as opposed to WLAN XML.

I agree with Kolink, but if you already have an XML scheme in place, I'd use XML to save you some headaches on the Java-side. It really depends on who's doing the most work. Also, JSON is more pact, so you could save bandwidth using its format.

There seem to be some libraries for parsing JSON in Java, so it may not be too hard to switch formats. http://json/java/

发布评论

评论列表(0)

  1. 暂无评论