Hello. How can I do that? I need to parse some string, but I don''t know if it''s a valid JSON string. If it is, I want to evaluate it, if not - to do something else. But evalJSON() works only if the string is valid, otherwise it returns an error... For example, how I can do it by PHP 5.2: if(is_array($res = json_decode($str,1))) print_r($res); else $xml = simplexml_load_file($str); something like that.. Thank you very much. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On 6/19/07, Alx <alx.flyweb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hello. > > How can I do that? > I need to parse some string, but I don''t know if it''s a valid JSON > string. If it is, I want to evaluate it, if not - to do something > else. But evalJSON() works only if the string is valid, otherwise it > returns an error... > > As of r7047 prototype contains a function isJSON() which does probablywhat you need: http://dev.rubyonrails.org/browser/spinoffs/prototype/branches/1-5-1-1/src/string.js?rev=7047#L170 Grtz, Gert --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
String#isJSON is also part of our 1.5.1.1 release. On Jun 19, 7:56 pm, "Gert Goet" <thinkcre...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 6/19/07, Alx <alx.fly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello. > > > How can I do that? > > I need to parse some string, but I don''t know if it''s a valid JSON > > string. If it is, I want to evaluate it, if not - to do something > > else. But evalJSON() works only if the string is valid, otherwise it > > returns an error... > > > As of r7047 prototype contains a function isJSON() which does probably > > what you need:http://dev.rubyonrails.org/browser/spinoffs/prototype/branches/1-5-1-... > > Grtz, > Gert--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
thank you very much, i''ve just done the same thing yesterday, but haven''t observed the new release :) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
oo new version, is there a changelog somewhere? On 6/20/07, Alx <alx.flyweb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > thank you very much, i''ve just done the same thing yesterday, but > haven''t observed the new release :) > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Alx, when all else fails Try, Catch will be your best friend. try{ eval(str); } catch(e){ //string isn''t valid } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hiya Alx, In the newest 1.5.1.1 bug fix release of Prototype there is a new String method called isJSON(); This should help you. http://www.prototypejs.org/2007/6/20/prototype-1-5-1-1-bugfix-release http://www.prototypejs.org/api/string/isJSON --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---