How to use JSON JavaScript to retrieve result in C?

4

I realized that JSON is used to communicate between systems. So it is possible to communicate with C, retrieving variables through a JSON generated by the code and send through the JavaScript AJAX response?

Or is there a better known technique for communication between systems, JavaScript [web] and C?

    
asked by anonymous 14.08.2015 / 05:18

1 answer

4

JSON is a data format. One of the things it is used for is communication between the client and the web server.

Each side does not need to know the technology on the other side, so there are standards that regulate communication.

In fact, the server does not need to know if it is serving a web browser, mobile application, desktop software or even another server. Much less need to know what technology is making the request, as long as it follows the established standards.

The same goes in the opposite direction. Essentially any programming language can be used to provide results for requesters as long as they follow these standards. And much of the standard can be served through a web server like Apache or IIS, so your C application just needs to know how to deliver the result to this server.

The data requested by JavaScript in a browser or can not be delivered in any format, as long as the requesting script knows what to do with it. Of course it is not common and it is not usually worth creating your own formats.

Initially the format proposed for use in asynchronous requests was XML. Hence the X of the name AJAX . But the format was considered cumbersome and complicated and was almost universally replaced by JSON, lighter and simpler.

Unless you have a good reason to choose another format or other form of communication, it is best to follow this same consecration.

So if your C application that will meet the requests received by the HTTP server is able to format the data in JSON, do this and it will be well served. If she is not able and can not solve this, she will have to choose a format and adapt JS to understand this format.

If you're doing something that will be consumed by a third party, it's best to use something pretty standard, even if you have one more difficulty, or even one layer more.

Some may find that a binary format can travel less data. This may be true in some situations. But it is possible to compress text data and reduce traffic. Depending on the amount of data it may not compensate. Adopting a binary format has complicating and catching of viable, it is not common to be adopted.

Do not do something different in C than you would in another language unless you have a requirement that requires a change.

    
14.08.2015 / 05:44