CHUVASH.eu

CHunky Universe of Vigourous Astonishing SHarepoint :)

json serializer in Sharepoint

There is a very handy JSON lib for serializing javascript objects. It is hosted on github under douglas crockford.

Download json2.js and serialize with JSON.stringify function:

EDIT: There is actually this function in core javascript. It exists since javascript 1.7 and ecmascript 5. So you don’t have to add anything to get this functionality:

var t = { name: "dev", city: "new york" };
JSON.stringify(t);

There are actually built-in goodies for serializing javascript objects in ASP.NET: Sys.Serialization.JavaScriptSerializer.serialize

var t = { name: "dev", city: "new york" };
Sys.Serialization.JavaScriptSerializer.serialize(t);


I discovered it when I “studied” the javascript code which follows with every page. Will see if more goodies can be discovered there:

var _spWebPermMasks = { High: 2147483647, Low: 4294967295 };
var _spPageStateActionControlId = 'ctl00_PageStateActionButton';
function GetPageNormalizedUrl() {
    alert('Denne koblingen for SharePoint Merker og kommentarer-verkt\u00F8yet er utdatert. Klikk OK for \u00E5 hente det nyeste Merker og kommentarer-verkt\u00F8yet. Klikk koblingen Mine merker i dialogboksen Merker og notatomr\u00E5det. Her f\u00E5r du tilgang det nye SharePoint Merker og kommentarer-verkt\u00F8yet.');
    return document.location.href;
}
var _openTagDialog_DialogUrl = '';
function OpenTagDialog(dialogUrl) {
    _openTagDialog_DialogUrl = dialogUrl;
    SafeRunFunction(_OpenTagDialogInternal, 'SocialData.js', 'TagDialogOpener');
}
function _OpenTagDialogInternal() {
    var normalizer = PageUrlNormalizer.GetInstance();
    normalizer.GetUrl('http:\u002f\u002fdev\u002fSider\u002fhei.aspx', function (normalizedUrl) {
        var url = _openTagDialog_DialogUrl + '?Title=' + encodeURIComponent(document.title)
			+ '&Src=' + 'bm' + '&DisplayUrl='
			+ encodeURIComponent(document.location.href)
			+ '&Url=' + encodeURIComponent(normalizedUrl);
        var options = 'toolbar=0,status=0,resizable=0,scrollbars=1,width=650,height=400';
        if (!window.open(url, null, options)) {
            document.location.href = url;
        }
    });
}
function InitializeSocialRibbonComponentWrapper_ctl00_ctl34() {
    SafeRunFunction(InitializeSocialRibbonComponent_ctl00_ctl34, 'sp.ui.socialribbon.js', 'SP.UI.SocialData.TRCRibbonComponent');
}
function InitializeSocialRibbonComponent_ctl00_ctl34() {
    SP.UI.SocialData.TRCRibbonComponent.RegisterWithPageManager();
    var ribbonComponent = SP.UI.SocialData.TRCRibbonComponent.get_Instance();
    ribbonComponent['EnableSocialComment'] = true;
    ribbonComponent['EnableSocialTag'] = true;
    ribbonComponent['ListID'] = '{59b06168-7ff3-4a36-9af4-e4fe3156b22a}';
    ribbonComponent['ResAddMessage'] = 'Legg til merke...';
    ribbonComponent['ResVerifyTypeMessage'] = 'Kontrollerer...';
    ribbonComponent.AddQuickTag = function (quickTagId) {
        SafeRunFunction(function () {
            var adder = new SocialQuickTag('ctl00_ctl34');
            adder.title = document.title;
            adder.url = 'http:\u002f\u002fdev\u002fSider\u002fhei.aspx';
            adder.tagged_text = 'Merket siden med Jeg liker det.';
            adder.failure_text = 'Kan ikke merke siden.';
            adder.AddQuickTag(quickTagId);
        }, 'SocialData.js', 'SocialQuickTag');
    };
    ribbonComponent.AddQuickTagToListItem = function (quickTagId) {
        var notificationId = addNotification("Legg til merke...", true);
        var listAndItemIds = this.SelectedListAndItemIds().split('|');
        var request = new Object(); request.listid = listAndItemIds[0];
        request.itemids = listAndItemIds[1];
        request.id = quickTagId;
        WebForm_DoCallback('ctl00$ctl34',
            Sys.Serialization.JavaScriptSerializer.serialize(request),
            Function.createDelegate(ribbonComponent, ribbonComponent._OnSucceededCallback), notificationId,
            Function.createDelegate(ribbonComponent, ribbonComponent._OnFailedCallback), true);
    };
    return ribbonComponent;
}
ExecuteOrDelayUntilScriptLoaded(InitializeSocialRibbonComponentWrapper_ctl00_ctl34, 'sp.ribbon.js');
function ctl00_ctl34_SocialNavControl_insertMyProfileMenu() {
    var menus = document.getElementsByTagName('menu');
    if (menus == null)
        return;
    var menu = null;
    for (var i = 0, len = menus.length; i < len; i++) {
        if (menus[i].id.lastIndexOf('PersonalActionMenu') != -1) {
            menu = menus[i]; break;
        }
    }
    if (menu == null) return;
    var elm = document.createElement('ie:menuitem');
    elm.setAttribute('menugroupid', '50');
    elm.setAttribute('description', 'Vis og administrer profilen.');
    elm.setAttribute('text', 'Min profil');
    elm.setAttribute('onmenuclick', 'STSNavigate2(event,\'http:\u002f\u002fdev:80\u002fmy\u002fPerson.aspx?accountname=CONTOSO\u00255CAdministrator\')');
    elm.setAttribute('id', 'ID_MySiteLinksMenu');
    var elm2 = document.createElement('ie:menuitem');
    elm2.setAttribute('menugroupid', '50');
    elm2.setAttribute('description', '\u00C5pne den personlige hjemmesiden');
    elm2.setAttribute('text', 'Mitt omr\u00E5de');
    elm2.setAttribute('onmenuclick', 'STSNavigate2(event,\'http:\u002f\u002fdev:80\u002fmy\u002f\')');
    elm2.setAttribute('id', 'ID_MySiteMenu');
    var sep = null;
    for (var i = 0, len = menu.childNodes.length; i < len; i++) {
        if (menu.childNodes[i].id == undefined || menu.childNodes[i].id == '') {
            sep = menu.childNodes[i];
            break;
        }
    }
    if (sep != null)
        menu.insertBefore(sep.cloneNode(true), menu.firstChild);
    menu.insertBefore(elm, menu.firstChild);
    if (sep != null)
        menu.insertBefore(sep.cloneNode(true), menu.firstChild);
    menu.insertBefore(elm2, menu.firstChild);
};
_spBodyOnLoadFunctionNames.push('ctl00_ctl34_SocialNavControl_insertMyProfileMenu');
function ctl00_ctl38_AddQuickTag() {
    SafeRunFunction(function () {
        var o = new SocialQuickTag('ctl00_ctl38');
        o.url = 'http:\u002f\u002fdev\u002fSider\u002fhei.aspx';
        o.title = document.title;
        o.tagged_text = 'Merket siden med Jeg liker det.';
        o.failure_text = 'Kan ikke merke siden.';
        o.replaceImg_style = 'border:0; left:-0px !important;top:-332px !important;position:absolute;';
        o.AddQuickTag(0);
    }, 'SocialData.js', 'SocialQuickTag');
}
function ctl00_ctl38_GetSocialNotification() {
    SafeRunFunction(function () {
        var o = new SocialTagsAndNotes('ctl00_ctl38');
        o.url = 'http:\u002f\u002fdev\u002fSider\u002fhei.aspx';
        o.tooltip = 'Merker hjelper deg \u00E5 huske koblinger og klassifisere siden. Kommentarene er offentlige. Merker og kommentarer legges inn i nyhetsfeeden og fungerer p\u00E5 tvers av forskjellige omr\u00E5der.';
        o.notify_text = '{0}-merker eller kommentarer p\u00E5 denne siden.  ';
        o.replaceImg_style = 'border:0; left:-0px !important;top:-332px !important;position:absolute;';
        o.GetSocialNotification();
    }, 'SocialData.js', 'SocialTagsAndNotes');
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Вула Чăвашла

VulaCV - Чăвашла вулаттаракан сайт

Discovering SharePoint

And going crazy doing it

Bram de Jager - Coder, Speaker, Author

Office 365, SharePoint and Azure

SharePoint Dragons

Nikander & Margriet on SharePoint

Paul J. Swider - RealActivity

RealActivity is a specialized healthcare services and solution advisory firm.

Mai Omar Desouki - Avid SharePointer

Egyptian & Vodafoner - Senior SharePoint Consultant

Cameron Dwyer | Office 365, SharePoint, Outlook, OnePlace Solutions

Office 365, SharePoint, OnePlace Solutions & Life's Other Little Wonders

paul.tavares

Me and My doings!

Share SharePoint Points !

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

Aryan Nava

| Blockchain | Serverless Architecture | Microservices Architecture | DevOps | AWS Lambda | Teraform |

SPJoel

SharePoint for everyone

SharePointRyan

Ryan Dennis is a SharePoint Solution Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint

blksthl

Mostly what I know about SharePoint - CommunicoCuspis

%d bloggers like this: