|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
json library jsonParse?Has anyone written a jsonParse or fromJson method/library they wish to
share? Why? I moved part of an application from 4D to RoR and need to set up a private web service in Active4D to talk to RoR. json is also a neat way of serializing a collection (that has nested collections) for storage. I created one several years ago based on a javascript port of <http://www.json.org/json_parse.js > to Active4D. It works and creates a collection - not the prettiest code in the world, but it even handled arrays with different types - converting them to a collection with a string index collection. I was just wondering if there was an "official" one out there. I thought about rewriting it using the state version <http://www.json.org/json_parse_state.js > and integrating it with a4d.json.a4l. That came to a halt when I found out that Active4d's Regex implementation must be different then javascripts. As a test, I tried this: $tx := '!^[\x20\t\n\r]*(?:([,:\[\]{}]|true|false|null)|(-?\d+(?:\.\d*)? (?:[eE][+\-]?\d+)?)|"((?:[^\r\n\t\\\"]|\\(?:["\\\/trnfb]|u[0-9a-fA-F] {4}))*)")!' $myJSONObject := """{"bindings": [ {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"}, {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"}, {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"} ] """ $cnt := regex match($tx;$myJSONObject;$results) but Active4D balked at character 126 saying a missing paren. I'm not event going begin to try to understand that regexp! Steve Alex P.S. I'll share my version if there is not an official one out there. _______________________________________________ Active4D-dev mailing list Active4D-dev@... http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/ |
|
|
Re: json library jsonParse?> I was just wondering if there was an "official" one out there.
Nothing "official". > $tx := '!^[\x20\t\n\r]*(?:([,:\[\]{}]|true|false|null)|(-?\d+(?:\. > \d*)?(?:[eE][+\-]?\d+)?)|"((?:[^\r\n\t\\\"]|\\(?:["\\\/trnfb]|u[0-9a- > fA-F]{4}))*)")!' > but Active4D balked at character 126 saying a missing paren. I'm not > event going begin to try to understand that regexp! Break it down: ! # opening delimiter ^ # anchor to start of string [\x20\t\n\r]* # match zero or more whitespace characters (space, tab, LF, CR) (?: # start a non-capturing group of alternates ( # capture group 1 [,:\[\]{}]|true|false|null # match the characters ,:[]{}, "true", "false", "null" ) # end capture group 1 | # OR ( # capture group 2 and so on. But the regexp syntax isn't the problem. The reason you are getting the error is because you have to double all of the backslashes, since they are inside a quoted string. In the original javascript the regex pattern is not within a string, so single backslashes are correct. Once you double all of the backslashes the pattern works correctly. Regards, Aparajita www.aparajitaworld.com "If you dare to fail, you are bound to succeed." - Sri Chinmoy | www.srichinmoy.org _______________________________________________ Active4D-dev mailing list Active4D-dev@... http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/ |
| Free embeddable forum powered by Nabble | Forum Help |