|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D.announce - AJAX+JSON RPC
I thought some might be interested in a flexible JSON RPC (AJAX with JSON instead of XML). http://web-gmui.svn.sourceforge.net/viewvc/web-gmui/trunk/json/JsonCore.d? revision=201&view=markup class Foo { Foo[] getFoos() { return [new Foo, new Foo]; } char[] getName() { return "myname"; } uint getId(uint i) { return i; } void advanced(char[] a, char[] b) {} } void main(char[][] args) { //don't need to be called, only instantiated. add!("Foo.getId"); add!("Foo.getName", "name"); //we set an optional alias add!("Foo.getFoos"); add!("Foo.advanced"); Foo foo = new Foo; //the string we could get from some client side JavaScript char[] input = "getFoos{getId(13),name}"; //the actual parsing char[] output = Parse!(Foo).parse(o, foo, input); /*output is now * `{0 : {getId : 13, name : "myname"}, 1 : { getId : 13, name : "myname"}}`); */ } The call Syntax is not JSON compatible, but the returned data is. add! accepts functions, class methods and global variables. An optional alias can also be set. You can call functions/methods with strings and numbers and arrays of those. Some examples: `getFoos[getId(13),name]` => `[{getId : 13, name : "myname"}, { getId : 13, name : "myname"}]`. `advanced("x","y"),name()bar` => `{advanced: null, bar : "myname"}`. Mar 12 2008
Reply to Moritz,I thought some might be interested in a flexible JSON RPC (AJAX with JSON instead of XML). Mar 12 2008
On Thu, 13 Mar 2008 01:35:09 +0000, BCS wrote:Reply to Moritz,I thought some might be interested in a flexible JSON RPC (AJAX with JSON instead of XML). Mar 12 2008
|