4 Replies Latest reply on Mar 30, 2012 8:20 AM by Simon Wood

    Ruby / JSON question



      trying to get a quick PoC up after attending the RhoElementsV2 day yesterday in Basingstoke. After a quick bit of advice on converting the JSON I've got out of a .net app to being parsable by the rho framework.


      Basically it's coming out fully escaped so looks like:


      "[ { \"Job\" { \"jobid\": \"123\", \"jobnumber\": \"1\"  


      and the default parse needs to have it as


      [ { "job": "123", "jobnumber": "1"


      I've looked int othe .net end and due to the way JSON is supported that seems to be how it is ! any suggestions for handling on the Ruby side.


      I know this is a V2 question rather than V1, but any advice greatfully received.



        • Re: Ruby / JSON question
          Derek Warren



            From your description I'm unable to tell if you are parsing the output in ruby from the .NET end. If not there is a 'json' ruby gem that performs parsing on a json.


          require 'json'


          test = "{ \"jobid\": \"123\", \"jobnumber\": \"1\"}"



          Returns: {"jobid"=>"123", "jobnumber"=>"1"}

          1 of 1 people found this helpful
            • Re: Ruby / JSON question



              is it legal to escape the double quote around the string primatives in JSON. DSW, you show it as escaped (which is what the .net output generates) but this causes an exception in the json gem used in RhoConnect. if I hand remove the escaping slashs all is fine.


              Looks like I'll have to throw away the WCF components and go with hand cranked HttpRequest and HttpResponse handling....


              Also if seems that once you have had an exception you have to close down every thing (terminate and remove the server debug session, close the client, restart all, force a log out on the client and log back in) before it stabilises again and will call the sync method.  Is there global state that is damaged by such exceptions ?

            • Ruby / JSON question

              Thanks - having played a bit more it appears I was generating poorly formed json over and above the quoting issue.  Was poor forming of the array vs object entities.


              New issue now which is preventing me from checking the fix but will raise under a seperate post.


              Thanks for the response.

                • Re: Ruby / JSON question

                  I worked around the issue using gsub gto get rid of the escape char on the quotes, but the root cause was returning a string rather than an object from .NET.  Coverting the web service to return the objects directly rather than a string representation solved the problem of the initial generation of the escape char.