Replacing JSON Libraries in Delphi REST Servers

本文介绍如何替换Delphi XE DataSnap REST Server应用中的JSON库以兼容jQuery插件,涉及具体文件修改和开源库选用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://blog.marcocantu.com/blog/json_libraries_delphi_rest.html

If you want to take advantage of jQuery and some of its plug-ins in a Delphi XE DataSnap REST Server application, you should replace the JSON processing library.

I've been working a lot with Delphi XE's DataSnap REST Server projects. I prepared a white paper for Embarcadero, and some introductory videos, and will host a webinar for the company in a couple of weeks (details should be made available soon). I'm also developing a couple of real world projects and building an add-in library (to be called "Delphi Rest Plus" or "Dwarf, Delphi Web Application Rest Framework" or soe other name I still have to figure out...). But that's for another post. Before I get to the actual topic, let me underline I like this new Delphi XE architecture a lot, but it is only a good foundation you have to build more on top.

So, getting to this specific post, if you want to take advantage of jQuery and some of its plug-ins in a Delphi XE DataSnap REST Server application, you should replace the JSON processing library that Embarcadero picked and that is causing lots of incompatibilities. That is the json-min.js file, an open source library by Brenton Fletcher. The specific issues I've had was with the "jQuery validation plug-in 1.7" (http://bassistance.de/jquery-plugins/jquery-plugin-validation/).

As a replacer, I picked the "most official" JavaScript parser for JSON, the public domain json2.js library you can find at http://www.JSON.org/json2.js and see the description at http://www.JSON.org/js.html. Now, of course, I also had to fix the some of the other JavaScript files generated by the DataSnap REST Application wizard in Delphi XE. I don't think I can provide the actual files (since they are proprietary), only list the changes.

In ServerFunctionsExecutor.js you have to change (around line 150) the first line below with the second:

   contentParam = contentParam.toJSONString(); // original
   contentParam = JSON.stringify(contentParam); // new

and (around line 180) you have to fix:

   JSONResultWrapper = responseText.parseJSON(); // original
   JSONResultWrapper = JSON.parse (responseText); // new

The first change (JSON.stringify for toJSONString) has to be done also in the ServerFunctionsInvoker.js file.

That's all for now, but stay tuned for other fixes and improvements to Delphi's REST support... and for the Embarcadero webinar.

PS. Still two more days only for the Extra Discount for Delphi Developer Days Europe: http://www.delphideveloperdays.com/.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值