0

using JSON in a YAP app

Hi,

Is there a way to parse JSON in a YAP app that is allowed by CAJA?

Thanks.

by
0 Replies
  • Hi Kramaley,

    Yes, there are a few ways you can do this. Below is a code sample that uses data from an object and then another from a JSON string. I'm guessing that you have a JSON string and you want to parse it to an object and are having problems with either JSON.parse or eval not being functional? In any event, gadgets.json.parse should work for that (shown below):

    CODE
    <div id='domEl' style='border:1px solid; margin-bottom:10px;'></div>
    <div id='domElTxt' style='border:1px solid;'></div>
    <script>
    //from object
    var myJSONObject = {"bindings": [
    {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
    {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
    {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
    ]
    };
    document.getElementById('domEl').innerHTML = myJSONObject.bindings[0].ircEvent;

    //from string
    var jsontext = '{"firstname":"Jesper","surname":"Aaberg","phone":["555-0100","555-0120"]}';
    var jsonTextData = gadgets.json.parse(jsontext);
    document.getElementById('domElTxt').innerHTML = jsonTextData.surname;
    </script>


    Jonathan LeBlanc
    Senior Software Engineer
    Yahoo! Developer Network

    QUOTE (Kramaley G @ Feb 5 2009, 02:37 AM) <{POST_SNAPBACK}>
    Hi,

    Is there a way to parse JSON in a YAP app that is allowed by CAJA?

    Thanks.
    0
  • Just to reference the other features available in gadgets.json, see: http://www.opensocial.org/Technical-Resour...08#gadgets.json

    - Jon
    0

Recent Posts

in YAP