Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EncodeJSON/DecodeJSON #23

Closed
melloware opened this issue Jan 28, 2021 · 1 comment
Closed

EncodeJSON/DecodeJSON #23

melloware opened this issue Jan 28, 2021 · 1 comment

Comments

@melloware
Copy link

melloware commented Jan 28, 2021

It looks like you removed these methods somewhere along the way but PF Extensions uses them.

            /**
             * Stringify a JSON hash so can save in a cookie or db-field
             */
            , encodeJSON: function (json) {
                var local = window.JSON || {};
                return (local.stringify || stringify)(json);

                function stringify(h) {
                    var D = [], i = 0, k, v, t // k = key, v = value
                        , a = $.isArray(h)
                    ;
                    for (k in h) {
                        v = h[k];
                        t = typeof v;
                        if (t == 'string')  // STRING - add quotes
                            v = '"' + v + '"';
                        else if (t == 'object') // SUB-KEY - recurse into it
                            v = parse(v);
                        D[i++] = (!a ? '"' + k + '":' : '') + v;
                    }
                    return (a ? '[' : '{') + D.join(',') + (a ? ']' : '}');
                }
            }

            /**
             * Convert stringified JSON back to a hash object
             * @see  $.parseJSON(), adding in jQuery 1.4.1
             */
            , decodeJSON: function (str) {
                try {
                    return JSON.parse(str);
                } catch (e) {
                    return {};
                }
            }
@melloware
Copy link
Author

Oh duh I guess I can just use JSON.stringify and JSON.parse?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant