MySpace Open Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

In v0.8 Strings are being parsed as false, numbers are fine

Last post 04-18-2009 4:55 PM by o1©. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 03-14-2009 12:16 AM

    • o1©
    • Top 150 Contributor
    • Joined on 04-24-2008
    • Posts 35

    In v0.8 Strings are being parsed as false, numbers are fine

    I am working on a much needed upgrade for my RSS Reader application and want to use v0.8.

    I am pretty much doing a complete rewrite using jQuery and v0.8.

    I am running into this problem where all the Strings that I had stored using v0.7 newUpdatePersonAppDataRequest are being read as false in v0.8.

    Here is my code that I came up with to read the v0.7 data in v0.8. I plan on doing a data conversion so that ultimately the app data gets stored using the myspace.com:123456 id format.

     Any input would be greatly appreciated. The following is the code I'm using to parse appdata.

        function readData() {
            $('#status').html('Loading...').fadeIn('slow');

            dataReqObj = opensocial.newDataRequest();

            var params = {};
            params[opensocial.IdSpec.Field.USER_ID] = opensocial.IdSpec.PersonId.OWNER;
            var idspec = opensocial.newIdSpec(params);       

            dataReqObj.add(dataReqObj.newFetchPersonRequest('VIEWER'), 'viewer');
            dataReqObj.add(dataReqObj.newFetchPersonAppDataRequest(idspec, '*'), 'viewer_data');
            dataReqObj.send(parseData);
        }

        function parseData(response) {
            var mydata = response.get('viewer_data');
            var viewer = response.get('viewer');
            userid = viewer.getData().getId();
           
           

            /* show error msg and error code */
            if (mydata.hadError()) {
                var thisErrorCode;
                var thisErrorMsg;
                if (response.get('viewer_data') != null) {
                    thisErrorCode = response.get('viewer_data').getErrorCode();
                    thisErrorMsg = response.get('viewer_data').getErrorMessage();
                } else {
                    thisErrorCode = "Unknown Error Code!";
                    thisErrorMsg = "Unknown Error Message!";
                }
                $('#status').html('A problem was encountered while trying loading your data. <br>' + 'ErrorCode: ' + thisErrorCode + ' | ' + 'Error Message: ' + thisErrorMsg).fadeIn('slow');
                return;
            }

            /* No errors so far keep going */
            var data = mydata.getData();

            /* Conversion from .7 data */
            if ( !data[userid] ) {
                userid = userid.replace('myspace.com:', '');
                var olddata = true;
            }

            /* $('#status').html(userid + dump(data[userid])); */
            /* $('#status').html(data[userid].bgcolor); */

            for( var varname in data[userid] ) {
                if ( $('#'+varname).length > 0 ) {
                    if ( $('#'+varname+':checkbox').length > 0) {
                        if (gadgets.json.parse(data[userid][varname]) == 'true' || gadgets.json.parse(data[userid][varname]) == 'on')
                            $('#'+varname).get(0).checked = true;
                        else
                            $('#'+varname).get(0).checked = false;
                    } else {

                        $('#'+varname).val(gadgets.json.parse(data[userid][varname]));
                    }
                }
            }

            $('#status').html('Data loaded...').fadeIn('slow');
        }

    Filed under:
  • 03-18-2009 10:35 AM In reply to

    Re: In v0.8 Strings are being parsed as false, numbers are fine

     I'll send the thread to our container folks, thanks for the feedback.
    Rhonda

     

  • 03-21-2009 11:54 AM In reply to

    • o1©
    • Top 150 Contributor
    • Joined on 04-24-2008
    • Posts 35

    Re: In v0.8 Strings are being parsed as false, numbers are fine

     Thank you looking into it. I hope someone can make sense of it soon.

     

    Owen

  • 03-23-2009 7:05 AM In reply to

    Re: In v0.8 Strings are being parsed as false, numbers are fine

     I sent to QA on wed or thurs, I can follow up today and see if they've had a chance to look at them.

    Rhonda

  • 03-23-2009 6:26 PM In reply to

    Re: In v0.8 Strings are being parsed as false, numbers are fine

     Hi, I'm not exactly sure what you mean. What kind of data is failing in gadgets.json.parse?

    Just to be clear what gadgets.json.parse does, you pass in a JSON string and it returns a JSON object representation, or the boolean false.

    So a string isn't a JSON string, so it should be parsed as false. A string wrapped in quotes is valid JSON.

    gadgets.json.parse("abc") //--> false

    gadgets.json.parse("\"abc\") //--> "abc"

    Numbers in string format should parse:

    gadgets.json.parse(123) //-->false

    gadgets.json.parse("123") //-->123

  • 03-24-2009 3:05 PM In reply to

    • o1©
    • Top 150 Contributor
    • Joined on 04-24-2008
    • Posts 35

    Re: In v0.8 Strings are being parsed as false, numbers are fine

    Ok, my app was built using v0.7. I am now trying to update to v0.8. I want to make the transition smooth for my users by ensuring no data is lost when I switch to the v0.8 version.

    In the 0.7 version I do not encode the data as JSON and that is the data I am trying to retrieve. I had actually left the gadgets.json.parse in the code because I was testing to see if that would fix my problem.

    Whether or not I use gadgets.json.parse any fields that have letters in them are returned as "false". I am referring to the array that is returned from var data = mydata.getData();  On the other hand, any fields that are stricly numeric, will actually parse fine and return a number to me.

    I found a javascript var dump function and below is a dump of the data array:

    'XXXXXXXXXXX' ... 'bgcolor' => "false" 'feedurl' => "false" 'linkcolor' => "false" 'rssreader_displayhtml' => "false" 'rssreader_maxitems' => "false" 'rssreader_maxlength' => "false" 'rssreader_rsslabel' => "false" 'txtcolor' => "false" 'rssreader_displayheight' => "550" 

     'XXXXXXXXXXX' is my userid, which incidently does not contain the prefix myspace.com: while the userid returned from: viewer.getData().getId(); does contain this prefix. I am wondering if this somehow is affecting my ability to retrieve the data? 

    I had to do something like this to get the correct userid key: userid = userid.replace('myspace.com:', '');

  • 03-26-2009 11:05 AM In reply to

    Re: In v0.8 Strings are being parsed as false, numbers are fine

    Ah, I see, thanks for the clarification.

    That would be a bug, in the 0.8 container we're assuming all data coming out of the data store is JSON, in this case it's not.  When the data comes back we call gadgets.json.parse on it, which will return 'false' for non-JSON.

    Instead, if the value doesn't parse, we should just be returning the original value as-is, we'll fix this bug shortly.

    Thanks for the heads up,

    Chad

  • 03-26-2009 12:26 PM In reply to

    • o1©
    • Top 150 Contributor
    • Joined on 04-24-2008
    • Posts 35

    Re: In v0.8 Strings are being parsed as false, numbers are fine

    Thank you very much.. I have everything else ready to go for my v0.8 upgrade, just waiting on this data conversion issue.

  • 03-30-2009 11:27 AM In reply to

    • o1©
    • Top 150 Contributor
    • Joined on 04-24-2008
    • Posts 35

    Re: In v0.8 Strings are being parsed as false, numbers are fine

     Hi Chad, any ETA on when this might be fixed?  I cannot publish my new code until I can access the old data.

  • 04-17-2009 10:57 AM In reply to

    Re: In v0.8 Strings are being parsed as false, numbers are fine

     Hi, this should now be fixed.

  • 04-18-2009 4:55 PM In reply to

    • o1©
    • Top 150 Contributor
    • Joined on 04-24-2008
    • Posts 35

    Re: In v0.8 Strings are being parsed as false, numbers are fine

    That's fantastic news! I can verify that it does indeed now work.

    Thank you!

Page 1 of 1 (11 items)